Skip to content

Fix printing parents in decompiler #4686

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 20, 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
57 changes: 31 additions & 26 deletions library/src/scala/tasty/util/ShowSourceCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,40 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
case TypeTree.TermSelect(Term.Select(Term.Ident("_root_"), "scala", _), "Product") => false
case _ => true
}
if (parents1.nonEmpty) {
sb.append(" extends")
parents1.foreach {
case parent@Term.Apply(Term.TypeApply(Term.Select(Term.New(tpt), _, _), targs), args) =>
this += " "
printTypeTree(tpt)
this += "["
printTypeOrBoundsTrees(targs, ", ")
this += "]"
if (args.nonEmpty) {
this += "("
printTrees(args, ", ")
this += ")"
}
if (parents1.nonEmpty)
this += " extends "

def printParent(parent: Parent): Unit = parent match {
case parent @ Term.TypeApply(fun, targs) =>
printParent(fun)
this += "["
printTypeOrBoundsTrees(targs, ", ")
this += "]"

case parent @ Term.Apply(fun, args) =>
printParent(fun)
this += "("
printTrees(args, ", ")
this += ")"

case parent@Term.Apply(Term.Select(Term.New(tpt), _, _), args) =>
this += " "
printTypeTree(tpt)
if (args.nonEmpty) {
this += "("
printTrees(args, ", ")
this += ")"
}
case parent @ Term.Select(Term.New(tpt), _, _) =>
printTypeTree(tpt)

case parent@TypeTree() =>
sb.append(" ")
printTypeTree(parent)
}
case parent @ TypeTree() =>
printTypeTree(parent)

case parent @ Term() => throw new MatchError(parent.show)
}

def printSeparated(list: List[Parent]): Unit = list match {
case Nil =>
case x :: Nil => printParent(x)
case x :: xs =>
printParent(x)
this += " with "
printSeparated(xs)
}
printSeparated(parents1)

def keepDefinition(d: Definition): Boolean = {
val flags = d.flags
Expand Down
11 changes: 11 additions & 0 deletions tests/pos/i1444.decompiled
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** Decompiled from out/posTestFromTasty/pos/i1444/Test.class */
object Test {
class Cls(implicit x: Test.X)
class ClsImpl() extends Test.Cls()(Test.AnX)
trait Tr1(implicit x: Test.X) extends java.lang.Object
class TrtImpl() extends Test.Tr1()(Test.AnX)
trait Tr2()(implicit x: Test.X) extends java.lang.Object
class Tr2Impl() extends Test.Tr2()(Test.AnX)
trait X() extends java.lang.Object
object AnX extends Test.X
}
2 changes: 1 addition & 1 deletion tests/pos/i2104b.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ case class Pair[A, B](_1: A, _2: B) {
throw new java.lang.IndexOutOfBoundsException(n.toString())
}
}
object Pair extends scala.AnyRef
object Pair extends scala.AnyRef()
/** Decompiled from out/posTestFromTasty/pos/i2104b/Test.class */
object Test {
def main(args: scala.Array[scala.Predef.String]): scala.Unit = {
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/simpleAnnot.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class Foo() {
def c(x: scala.Int): scala.Int = (x: @annot())
}
/** Decompiled from out/posTestFromTasty/pos/simpleAnnot/annot.class */
class annot() extends scala.annotation.Annotation
class annot() extends scala.annotation.Annotation()
2 changes: 1 addition & 1 deletion tests/pos/simpleCaseClass-3.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ case class A[T](x: T) {
throw new java.lang.IndexOutOfBoundsException(n.toString())
}
}
object A extends scala.AnyRef
object A extends scala.AnyRef()
2 changes: 1 addition & 1 deletion tests/pos/simpleClass-2.decompiled
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Decompiled from out/posTestFromTasty/pos/simpleClass-2/foo/A.class */
package foo {
class A() extends foo.B
class A() extends foo.B()
}
/** Decompiled from out/posTestFromTasty/pos/simpleClass-2/foo/B.class */
package foo {
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/simpleClass-3.decompiled
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** Decompiled from out/posTestFromTasty/pos/simpleClass-3/A.class */
class A() extends B with C
/** Decompiled from out/posTestFromTasty/pos/simpleClass-3/B.class */
trait B() extends java.lang.Object
/** Decompiled from out/posTestFromTasty/pos/simpleClass-3/C.class */
trait C() extends java.lang.Object
5 changes: 5 additions & 0 deletions tests/pos/simpleClass-3.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

trait B
trait C

class A extends B with C
2 changes: 1 addition & 1 deletion tests/pos/simpleClass.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ package foo {
}
/** Decompiled from out/posTestFromTasty/pos/simpleClass/foo/B.class */
package foo {
class B() extends foo.A
class B() extends foo.A()
}
4 changes: 2 additions & 2 deletions tests/run/simpleClass.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ package foo {
}
/** Decompiled from out/runTestFromTasty/run/simpleClass/foo/B.class */
package foo {
class B() extends foo.A
}
class B() extends foo.A()
}