-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Update ReTyper to Ycheck patterns & inline fixes #3143
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
Update ReTyper to Ycheck patterns & inline fixes #3143
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM
@@ -512,8 +512,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => | |||
val (meth, targs, argss) = decomposeCall(fn) | |||
(meth, targs, argss :+ args) | |||
case TypeApply(fn, targs) => | |||
val (meth, Nil, Nil) = decomposeCall(fn) | |||
(meth, targs, Nil) | |||
val (meth, targss, args) = decomposeCall(fn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the change. Can you give an example where this matters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test added in the same commit (e199fc8) breaks with a match error before the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be much more efficient to implement this methods as:
def decomposeCall(tree: Tree): (Tree, List[Tree], List[List[Tree]]) = {
@tailrec def loop(tree: Tree, targs: List[Tree], argss: List[List[Tree]]): (Tree, List[Tree], List[List[Tree]]) =
tree match {
case Apply(fn, args) =>
loop(fn, targs, args :: argss)
case TypeApply(fn, targs) =>
loop(fn, targs, argss)
case _ =>
(tree, targs, argss)
}
loop(tree, Nil, Nil)
}
@@ -962,9 +962,10 @@ trait Applications extends Compatibility { self: Typer with Dynamic => | |||
|
|||
val dummyArg = dummyTreeOfType(ownType) | |||
val unapplyApp = typedExpr(untpd.TypedSplice(Apply(unapplyFn, dummyArg :: Nil))) | |||
val unapplyImplicits = unapplyApp match { | |||
def unapplyImplicits(unapp: Tree = unapplyApp): List[Tree] = unapp match { | |||
case Apply(Apply(unapply, `dummyArg` :: Nil), args2) => assert(args2.nonEmpty); args2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's safer in that case to not have a default argument for unapp
.
@@ -48,11 +52,22 @@ class ReTyper extends Typer { | |||
override def typedSuper(tree: untpd.Super, pt: Type)(implicit ctx: Context): Tree = | |||
promote(tree) | |||
|
|||
override def typedTyped(tree: untpd.Typed, pt: Type)(implicit ctx: Context): Tree = { | |||
assertTyped(tree) | |||
val type1 = checkSimpleKinded(typedType(tree.tpt)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename type1 -> tpt1
, tree1 -> expr1
to conform to naming conventions used elsewhere. (tpt
stands for "type tree")
26a240b
to
b9db9f6
Compare
Completely forgot about this PR 😅. I've addressed the review and rebased, so it should be good to go! |
final class Foo(val value: Int) | ||
|
||
object Foo { | ||
inline def unapplySeq(foo: Foo): Some[Seq[Int]] = Some(List(foo.value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be changed to inline def unapply(foo: Foo)
after #3747?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say not for now, if/when unapplySeq
is effectively not supported in Dotty then we should turn this tests into a scala2 test.
2d846fc
to
9c70648
Compare
See i3248.scala for an example of a non case class pattern leaking scala.annotation.internal.Repeated.
9c70648
to
a506b50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just needs another rebase. LGTM.
This PR does minor adjustments to Typer and ReTyper such that patterns pass Ycheck. This is required to be able to inline pattern matching expressions.