Skip to content

Commit df3c9b5

Browse files
authored
Merge pull request #4640 from dotty-staging/fix-tasty-pattern-bind
Fix tasty reflect pattern binds when typed
2 parents 61355f0 + 1f9af0e commit df3c9b5

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ object TastyImpl extends scala.tasty.Tasty {
488488

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

503504
object TypeTest extends TypeTestExtractor {
504505
def unapply(x: Pattern)(implicit ctx: Context): Option[TypeTree] = x match {
505-
case x: tpd.Typed @unchecked => Some(x.tpt)
506+
case Trees.Typed(Trees.UnApply(_, _, _), _) => None
507+
case Trees.Typed(_, tpt) => Some(tpt)
506508
case _ => None
507509
}
508510
}

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
559559
printTypeTree(tpt)
560560

561561
case Pattern.Bind(name, pattern) =>
562-
this += name += "@ "
562+
this += name += " @ "
563563
printPattern(pattern)
564564

565565
case Pattern.Unapply(fun, implicits, patterns) =>

tests/pos/simpleExractors.decompiled renamed to tests/pos/simpleExtractors-1.decompiled

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
/** Decompiled from out/posTestFromTasty/pos/simpleExractors/Bar.class */
1+
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-1/Bar.class */
22
object Bar {
33
def unapply(arg: scala.Any): scala.Option[scala.Any] = scala.Some.apply[scala.Any](arg)
44
}
5-
/** Decompiled from out/posTestFromTasty/pos/simpleExractors/BarSeq.class */
5+
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-1/BarSeq.class */
66
object BarSeq {
77
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))
88
}
9-
/** Decompiled from out/posTestFromTasty/pos/simpleExractors/Baz.class */
9+
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-1/Baz.class */
1010
object Baz {
1111
def unapply[T](arg: T): scala.Option[T] = scala.Some.apply[T](arg)
1212
}
13-
/** Decompiled from out/posTestFromTasty/pos/simpleExractors/BazSeq.class */
13+
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-1/BazSeq.class */
1414
object BazSeq {
1515
def unapplySeq[T](arg: T): scala.Option[scala.Seq[T]] = scala.Some.apply[collection.immutable.List[T]](scala.List.apply[T](arg))
1616
}
17-
/** Decompiled from out/posTestFromTasty/pos/simpleExractors/Foo.class */
17+
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-1/Foo.class */
1818
class Foo() {
1919
def bar(x: scala.Any): scala.Unit = x match {
2020
case Bar(a) =>
File renamed without changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** Decompiled from out/posTestFromTasty/pos/simpleExtractors-2/Foo.class */
2+
class Foo() {
3+
def bar(x: scala.Any): scala.Unit = x match {
4+
case scala.Some(scala.Some(i: scala.Int)) =>
5+
scala.Predef.println(i)
6+
case scala.Some(s @ scala.Some(i)) =>
7+
scala.Predef.println(s)
8+
case s @ scala.Some(r @ scala.Some(i)) =>
9+
scala.Predef.println(s)
10+
}
11+
}

tests/pos/simpleExtractors-2.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Foo {
2+
def bar(x: Any): Unit = x match {
3+
case Some(Some(i: Int)) => println(i)
4+
case Some(s @ Some(i)) => println(s)
5+
case s @ Some(r @ Some(i)) => println(s)
6+
}
7+
}

0 commit comments

Comments
 (0)