Skip to content

Commit 057b061

Browse files
committed
Fix printing parents
* Fixed multiple argument list constructors * Added missing `with` in between the parents
1 parent 8b2500e commit 057b061

10 files changed

+60
-33
lines changed

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

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,35 +88,40 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
8888
case TypeTree.TermSelect(Term.Select(Term.Ident("_root_"), "scala", _), "Product") => false
8989
case _ => true
9090
}
91-
if (parents1.nonEmpty) {
92-
sb.append(" extends")
93-
parents1.foreach {
94-
case parent@Term.Apply(Term.TypeApply(Term.Select(Term.New(tpt), _, _), targs), args) =>
95-
this += " "
96-
printTypeTree(tpt)
97-
this += "["
98-
printTypeOrBoundsTrees(targs, ", ")
99-
this += "]"
100-
if (args.nonEmpty) {
101-
this += "("
102-
printTrees(args, ", ")
103-
this += ")"
104-
}
91+
if (parents1.nonEmpty)
92+
this += " extends "
93+
94+
def printParent(parent: Parent): Unit = parent match {
95+
case parent @ Term.TypeApply(fun, targs) =>
96+
printParent(fun)
97+
this += "["
98+
printTypeOrBoundsTrees(targs, ", ")
99+
this += "]"
100+
101+
case parent @ Term.Apply(fun, args) =>
102+
printParent(fun)
103+
this += "("
104+
printTrees(args, ", ")
105+
this += ")"
105106

106-
case parent@Term.Apply(Term.Select(Term.New(tpt), _, _), args) =>
107-
this += " "
108-
printTypeTree(tpt)
109-
if (args.nonEmpty) {
110-
this += "("
111-
printTrees(args, ", ")
112-
this += ")"
113-
}
107+
case parent @ Term.Select(Term.New(tpt), _, _) =>
108+
printTypeTree(tpt)
114109

115-
case parent@TypeTree() =>
116-
sb.append(" ")
117-
printTypeTree(parent)
118-
}
110+
case parent @ TypeTree() =>
111+
printTypeTree(parent)
112+
113+
case parent @ Term() => throw new MatchError(parent.show)
114+
}
115+
116+
def printSeparated(list: List[Parent]): Unit = list match {
117+
case Nil =>
118+
case x :: Nil => printParent(x)
119+
case x :: xs =>
120+
printParent(x)
121+
this += " with "
122+
printSeparated(xs)
119123
}
124+
printSeparated(parents1)
120125

121126
def keepDefinition(d: Definition): Boolean = {
122127
val flags = d.flags

tests/pos/i1444.decompiled

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** Decompiled from out/posTestFromTasty/pos/i1444/Test.class */
2+
object Test {
3+
class Cls(implicit x: Test.X)
4+
class ClsImpl() extends Test.Cls()(Test.AnX)
5+
trait Tr1(implicit x: Test.X) extends java.lang.Object
6+
class TrtImpl() extends Test.Tr1()(Test.AnX)
7+
trait Tr2()(implicit x: Test.X) extends java.lang.Object
8+
class Tr2Impl() extends Test.Tr2()(Test.AnX)
9+
trait X() extends java.lang.Object
10+
object AnX extends Test.X
11+
}

tests/pos/i2104b.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ case class Pair[A, B](_1: A, _2: B) {
3131
throw new java.lang.IndexOutOfBoundsException(n.toString())
3232
}
3333
}
34-
object Pair extends scala.AnyRef
34+
object Pair extends scala.AnyRef()
3535
/** Decompiled from out/posTestFromTasty/pos/i2104b/Test.class */
3636
object Test {
3737
def main(args: scala.Array[scala.Predef.String]): scala.Unit = {

tests/pos/simpleAnnot.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ class Foo() {
66
def c(x: scala.Int): scala.Int = (x: @annot())
77
}
88
/** Decompiled from out/posTestFromTasty/pos/simpleAnnot/annot.class */
9-
class annot() extends scala.annotation.Annotation
9+
class annot() extends scala.annotation.Annotation()

tests/pos/simpleCaseClass-3.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ case class A[T](x: T) {
2222
throw new java.lang.IndexOutOfBoundsException(n.toString())
2323
}
2424
}
25-
object A extends scala.AnyRef
25+
object A extends scala.AnyRef()

tests/pos/simpleClass-2.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** Decompiled from out/posTestFromTasty/pos/simpleClass-2/foo/A.class */
22
package foo {
3-
class A() extends foo.B
3+
class A() extends foo.B()
44
}
55
/** Decompiled from out/posTestFromTasty/pos/simpleClass-2/foo/B.class */
66
package foo {

tests/pos/simpleClass-3.decompiled

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** Decompiled from out/posTestFromTasty/pos/simpleClass-3/A.class */
2+
class A() extends B with C
3+
/** Decompiled from out/posTestFromTasty/pos/simpleClass-3/B.class */
4+
trait B() extends java.lang.Object
5+
/** Decompiled from out/posTestFromTasty/pos/simpleClass-3/C.class */
6+
trait C() extends java.lang.Object

tests/pos/simpleClass-3.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
trait B
3+
trait C
4+
5+
class A extends B with C

tests/pos/simpleClass.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ package foo {
44
}
55
/** Decompiled from out/posTestFromTasty/pos/simpleClass/foo/B.class */
66
package foo {
7-
class B() extends foo.A
7+
class B() extends foo.A()
88
}

tests/run/simpleClass.decompiled

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ package foo {
1111
}
1212
/** Decompiled from out/runTestFromTasty/run/simpleClass/foo/B.class */
1313
package foo {
14-
class B() extends foo.A
15-
}
14+
class B() extends foo.A()
15+
}

0 commit comments

Comments
 (0)