Skip to content

Commit cfed294

Browse files
committed
Fix extractors printing
1 parent a9f3e95 commit cfed294

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

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

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

513513
case Pattern.Unapply(fun, implicits, patterns) =>
514-
printTree(fun)
514+
fun match {
515+
case Term.Select(extractor, "unapply" | "unapplySeq", _) => printTree(extractor)
516+
case Term.TypeApply(Term.Select(extractor, "unapply" | "unapplySeq", _), _) => printTree(extractor)
517+
case _ => throw new MatchError(fun.show)
518+
}
515519
this += "("
516520
printPatterns(patterns, ", ")
517521
this += ")"
@@ -520,7 +524,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
520524
printPatterns(trees, " | ")
521525

522526
case Pattern.TypeTest(tpt) =>
523-
this
527+
this += "_: "
528+
printTypeOrBoundsTree(tpt)
524529

525530
}
526531

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

0 commit comments

Comments
 (0)