From 1a7eadead11ea194ef58a13d1975f516ab3f2710 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 20 Jun 2018 21:54:45 +0200 Subject: [PATCH] Fix printing of secondary constructors --- library/src/scala/tasty/util/ShowSourceCode.scala | 15 +++++++++++---- tests/pos/t116.decompiled | 8 ++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 tests/pos/t116.decompiled diff --git a/library/src/scala/tasty/util/ShowSourceCode.scala b/library/src/scala/tasty/util/ShowSourceCode.scala index d57cb8233f2c..408ae1a61e0e 100644 --- a/library/src/scala/tasty/util/ShowSourceCode.scala +++ b/library/src/scala/tasty/util/ShowSourceCode.scala @@ -222,13 +222,17 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty if (flags.isInline) this += "inline " if (flags.isOverride) this += "override " - this += "def " += name + val isConstructor = name == "" + + this += "def " += (if (isConstructor) "this" else name) printTargsDefs(targs) val it = argss.iterator while (it.hasNext) printArgsDefs(it.next()) - this += ": " - printTypeTree(tpt) + if (!isConstructor) { + this += ": " + printTypeTree(tpt) + } rhs match { case Some(tree) => this += " = " @@ -265,7 +269,10 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty printTree(expr) case Term.Apply(fn, args) => - printTree(fn) + fn match { + case Term.Select(Term.This(_), "", _) => this += "this" // call to constructor inside a constructor + case _ => printTree(fn) + } this += "(" printTrees(args, ", ") this += ")" diff --git a/tests/pos/t116.decompiled b/tests/pos/t116.decompiled new file mode 100644 index 000000000000..269193c97eb2 --- /dev/null +++ b/tests/pos/t116.decompiled @@ -0,0 +1,8 @@ +/** Decompiled from out/posTestFromTasty/pos/t116/C.class */ +class C() { + def this(x: scala.Int) = { + this() + class D() extends C() + () + } +}