Skip to content

Fix tasty reflect pattern binds when typed #4640

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 1 commit into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ object TastyImpl extends scala.tasty.Tasty {

object Unapply extends UnapplyExtractor {
def unapply(x: Pattern)(implicit ctx: Context): Option[(Term, List[Term], List[Pattern])] = x match {
case x: tpd.UnApply @unchecked => Some(x.fun, x.implicits, x.patterns)
case Trees.UnApply(fun, implicits, patterns) => Some((fun, implicits, patterns))
case Trees.Typed(Trees.UnApply(fun, implicits, patterns), _) => Some((fun, implicits, patterns))
case _ => None
}
}
Expand All @@ -502,7 +503,8 @@ object TastyImpl extends scala.tasty.Tasty {

object TypeTest extends TypeTestExtractor {
def unapply(x: Pattern)(implicit ctx: Context): Option[TypeTree] = x match {
case x: tpd.Typed @unchecked => Some(x.tpt)
case Trees.Typed(Trees.UnApply(_, _, _), _) => None
case Trees.Typed(_, tpt) => Some(tpt)
case _ => None
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/tasty/util/ShowSourceCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
printTypeTree(tpt)

case Pattern.Bind(name, pattern) =>
this += name += "@ "
this += name += " @ "
printPattern(pattern)

case Pattern.Unapply(fun, implicits, patterns) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/** Decompiled from out/posTestFromTasty/pos/simpleExractors/Bar.class */
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-1/Bar.class */
object Bar {
def unapply(arg: scala.Any): scala.Option[scala.Any] = scala.Some.apply[scala.Any](arg)
}
/** Decompiled from out/posTestFromTasty/pos/simpleExractors/BarSeq.class */
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-1/BarSeq.class */
object BarSeq {
def unapplySeq(arg: scala.Any): scala.Option[scala.Seq[scala.Any]] = scala.Some.apply[collection.immutable.List[scala.Any]](scala.List.apply[scala.Any](arg))
}
/** Decompiled from out/posTestFromTasty/pos/simpleExractors/Baz.class */
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-1/Baz.class */
object Baz {
def unapply[T](arg: T): scala.Option[T] = scala.Some.apply[T](arg)
}
/** Decompiled from out/posTestFromTasty/pos/simpleExractors/BazSeq.class */
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-1/BazSeq.class */
object BazSeq {
def unapplySeq[T](arg: T): scala.Option[scala.Seq[T]] = scala.Some.apply[collection.immutable.List[T]](scala.List.apply[T](arg))
}
/** Decompiled from out/posTestFromTasty/pos/simpleExractors/Foo.class */
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-1/Foo.class */
class Foo() {
def bar(x: scala.Any): scala.Unit = x match {
case Bar(a) =>
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions tests/pos/simpleExtractors-2.decompiled
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-2/Foo.class */
class Foo() {
def bar(x: scala.Any): scala.Unit = x match {
case scala.Some(scala.Some(i: scala.Int)) =>
scala.Predef.println(i)
case scala.Some(s @ scala.Some(i)) =>
scala.Predef.println(s)
case s @ scala.Some(r @ scala.Some(i)) =>
scala.Predef.println(s)
}
}
7 changes: 7 additions & 0 deletions tests/pos/simpleExtractors-2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Foo {
def bar(x: Any): Unit = x match {
case Some(Some(i: Int)) => println(i)
case Some(s @ Some(i)) => println(s)
case s @ Some(r @ Some(i)) => println(s)
}
}