Skip to content

Commit a558a81

Browse files
committed
Fix extractors printing
1 parent aab7c7f commit a558a81

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,11 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
508508
printPattern(pattern)
509509

510510
case Pattern.Unapply(fun, implicits, patterns) =>
511-
printTree(fun)
511+
fun match {
512+
case Term.Select(extractor, "unapply" | "unapplySeq", _) => printTree(extractor)
513+
case Term.TypeApply(Term.Select(extractor, "unapply" | "unapplySeq", _), _) => printTree(extractor)
514+
case _ => throw new MatchError(fun.show)
515+
}
512516
this += "("
513517
printPatterns(patterns, ", ")
514518
this += ")"
@@ -517,7 +521,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
517521
printPatterns(trees, " | ")
518522

519523
case Pattern.TypeTest(tpt) =>
520-
this
524+
this += "_: "
525+
printTypeOrBoundsTree(tpt)
521526

522527
}
523528

tests/pos/simpleExractors.decompiled

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/** Decompiled from out/posTestFromTasty/pos/simpleExractors/Bar.class */
2+
object Bar {
3+
def unapply(arg: scala.Any): scala.Option[scala.Any] = scala.Some.apply[scala.Any](arg)
4+
}/** Decompiled from out/posTestFromTasty/pos/simpleExractors/BarSeq.class */
5+
object BarSeq {
6+
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))
7+
}/** Decompiled from out/posTestFromTasty/pos/simpleExractors/Baz.class */
8+
object Baz {
9+
def unapply[T](arg: T): scala.Option[T] = scala.Some.apply[T](arg)
10+
}/** Decompiled from out/posTestFromTasty/pos/simpleExractors/BazSeq.class */
11+
object BazSeq {
12+
def unapplySeq[T](arg: T): scala.Option[scala.Seq[T]] = scala.Some.apply[collection.immutable.List[T]](scala.List.apply[T](arg))
13+
}/** Decompiled from out/posTestFromTasty/pos/simpleExractors/Foo.class */
14+
class Foo() {
15+
def bar(x: scala.Any): scala.Unit = x match {
16+
case Bar(a) =>
17+
{
18+
scala.Predef.println(a)
19+
}
20+
case BarSeq(a) =>
21+
{
22+
scala.Predef.println(a)
23+
}
24+
case BarSeq(a, b) =>
25+
{
26+
scala.Predef.println(a)
27+
}
28+
}
29+
def baz(x: scala.Any): scala.Unit = x match {
30+
case Baz(a) =>
31+
{
32+
scala.Predef.println(a)
33+
}
34+
case BazSeq(a) =>
35+
{
36+
scala.Predef.println(a)
37+
}
38+
case BazSeq(a, b) =>
39+
{
40+
scala.Predef.println(a)
41+
}
42+
}
43+
}

tests/pos/simpleExractors.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Foo {
2+
def bar(x: Any): Unit = x match {
3+
case Bar(a) => println(a)
4+
case BarSeq(a) => println(a)
5+
case BarSeq(a, b) => println(a)
6+
}
7+
def baz(x: Any): Unit = x match {
8+
case Baz(a) => println(a)
9+
case BazSeq(a) => println(a)
10+
case BazSeq(a, b) => println(a)
11+
}
12+
}
13+
14+
object Bar {
15+
def unapply(arg: Any): Option[Any] = Some(arg)
16+
}
17+
18+
object BarSeq {
19+
def unapplySeq(arg: Any): Option[Seq[Any]] = Some(List(arg))
20+
}
21+
22+
object Baz {
23+
def unapply[T](arg: T): Option[T] = Some(arg)
24+
}
25+
26+
object BazSeq {
27+
def unapplySeq[T](arg: T): Option[Seq[T]] = Some(List(arg))
28+
}

tests/run/tasty-custom-show/quoted_1.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ object Macros {
4848
class DummyShow[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty0) {
4949
import tasty._
5050
def showTree(tree: Tree)(implicit ctx: Context): String = "Tree"
51+
def showPattern(pattern: Pattern)(implicit ctx: Context): String = "Pattern"
5152
def showTypeOrBoundsTree(tpt: TypeOrBoundsTree)(implicit ctx: Context): String = "TypeOrBoundsTree"
5253
def showTypeOrBounds(tpe: TypeOrBounds)(implicit ctx: Context): String = "TypeOrBounds"
5354
def showConstant(const: Constant)(implicit ctx: Context): String = "Constant"

0 commit comments

Comments
 (0)