diff options
-rw-r--r-- | src/reflect/scala/reflect/internal/BuildUtils.scala | 8 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/TypecheckedProps.scala | 25 |
2 files changed, 30 insertions, 3 deletions
diff --git a/src/reflect/scala/reflect/internal/BuildUtils.scala b/src/reflect/scala/reflect/internal/BuildUtils.scala index b9458e4b09..6f2cb239c5 100644 --- a/src/reflect/scala/reflect/internal/BuildUtils.scala +++ b/src/reflect/scala/reflect/internal/BuildUtils.scala @@ -163,9 +163,11 @@ trait BuildUtils { self: SymbolTable => def apply(tree: Tree, argss: List[List[Tree]]): Tree = argss.foldLeft(tree) { (f, args) => Apply(f, args.map(treeInfo.assignmentToMaybeNamedArg)) } - def unapply(tree: Tree): Some[(Tree, List[List[Tree]])] = { - val treeInfo.Applied(fun, targs, argss) = tree - Some((SyntacticTypeApplied(fun, targs), argss)) + def unapply(tree: Tree): Some[(Tree, List[List[Tree]])] = tree match { + case UnApply(treeInfo.Unapplied(Select(fun, nme.unapply)), pats) => + Some((fun, pats :: Nil)) + case treeInfo.Applied(fun, targs, argss) => + Some((SyntacticTypeApplied(fun, targs), argss)) } } diff --git a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala index f443330e0b..2f501435e3 100644 --- a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala +++ b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala @@ -50,4 +50,29 @@ object TypecheckedProps extends QuasiquoteProperties("typechecked") { assert(enums1 ≈ enums) assert(body1 ≈ body) } + + property("extract UnApply (1)") = test { + val q"object $_ { $_; $_; $m }" = typecheck(q""" + object Test { + class Cell(val x: Int) + object Cell { def unapply(c: Cell) = Some(c.x) } + new Cell(0) match { case Cell(v) => v } + } + """) + val q"$_ match { case $f(..$args) => $_ }" = m + assert(f ≈ pq"Test.this.Cell") + assert(args ≈ List(pq"v")) + } + + property("extract UnApply (2)") = test { + val q"object $_ { $_; $_; $m }" = typecheck(q""" + object Test { + case class Cell(val x: Int) + new Cell(0) match { case Cell(v) => v } + } + """) + val q"$_ match { case ${f: TypeTree}(..$args) => $_ }" = m + assert(f.original ≈ pq"Test.this.Cell") + assert(args ≈ List(pq"v")) + } }
\ No newline at end of file |