Skip to content

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

Merged
merged 9 commits into from
Feb 12, 2018

Conversation

OlivierBlanvillain
Copy link
Contributor

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.

Copy link
Contributor

@odersky odersky left a 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)
Copy link
Contributor

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?

Copy link
Contributor Author

@OlivierBlanvillain OlivierBlanvillain Jan 18, 2018

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

Copy link
Contributor

@allanrenucci allanrenucci Jan 22, 2018

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
Copy link
Contributor

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))
Copy link
Contributor

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")

@OlivierBlanvillain
Copy link
Contributor Author

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))
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@odersky odersky left a 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.

@odersky odersky removed their assignment Feb 12, 2018
@OlivierBlanvillain OlivierBlanvillain merged commit 2729819 into scala:master Feb 12, 2018
@allanrenucci allanrenucci deleted the ycheck-patterns branch April 11, 2018 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants