Skip to content

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

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

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.


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