-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Proposal for replacing IsXxx extractors in tasty-reflect #7204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I suspect it won't work with types that share the same runtime representation. I did try this pattern in the past and something was a miss. I will double check. |
Unfortunately the val t1: Reflection = ...
val t2: Reflection = ...
val tree: t1.Tree = ...
tree match {
case t2.IsImport(tree) =>
} |
The closest to a good and simple to use solution I've got is in dotty-staging@3fa4592. This is a rebase of an old PR that was closed. |
|
trait Castable[U, T <: U] {
def cast(t: U): Option[T]
}
trait Typable[T] extends Castable[Any, T] {
def cast(t: Any): Option[T]
...
} Then in the reflect interface we would provide instances for given ValDefIsTypeable(given Context): Castable[Tree, ValDef] {
def cast(t: Tree): Option[ValDef] = ...
} |
I've no objections to That said, I'm not convinced that this is the right answer to the particular problem expressed in this PR ... surely there's a design out there that wouldn't require |
* Deprecate `IsXYZ` extrators * Provide `IsInstanceOf[XYZ]` evidences * Refine the types of arguments of `unapply`s * Use `_: XYZ` instead of `IsXYZ(_)` in the dotty library
* Deprecate `IsXYZ` extrators * Provide `IsInstanceOf[XYZ]` evidences * Refine the types of arguments of `unapply`s * Use `_: XYZ` instead of `IsXYZ(_)` in the dotty library
* Deprecate `IsXYZ` extrators * Provide `IsInstanceOf[XYZ]` evidences * Refine the types of arguments of `unapply`s * Use `_: XYZ` instead of `IsXYZ(_)` in the dotty library
Fix #7204: Use evidence based type testing for unapplies
https://github.com/lampepfl/dotty/blob/master/library/src/scala/tasty/reflect/TreeOps.scala uses the following pattern:
Which leads to usesites like this:
The use of
IsImport
does not feel very natural, I think the following pattern could be used instead:Note the use of
@unchecked
at the definition site to avoid unchecked warnings at use-site, this is still safe since the pattern won't match if the tree isn't actually an Import node.WDYT @nicolasstucki ?
The text was updated successfully, but these errors were encountered: