Skip to content

Commit af822e1

Browse files
committed
Do not print extends Object whlie decompiling
1 parent 2ea9d9e commit af822e1

10 files changed

+16
-12
lines changed

compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools.dotc.printing
22

3-
import dotty.tools.dotc.ast.Trees.{Closure, DefDef, Untyped, ValDef}
3+
import dotty.tools.dotc.ast.Trees._
44
import dotty.tools.dotc.ast.untpd.{PackageDef, Template, TypeDef}
55
import dotty.tools.dotc.ast.{Trees, untpd}
66
import dotty.tools.dotc.printing.Texts._
@@ -49,6 +49,12 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
4949
decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~ ""
5050
}
5151

52+
override protected def toTextTemplate(impl: Template, ofNew: Boolean = false): Text = {
53+
val Template(constr, parents, self, preBody) = impl
54+
val impl1 = Template(constr, parents.filterNot(_.symbol.maybeOwner == defn.ObjectClass), self, preBody)
55+
super.toTextTemplate(impl1, ofNew)
56+
}
57+
5258
override protected def defDefToText[T >: Untyped](tree: DefDef[T]): Text = {
5359
import untpd.{modsDeco => _, _}
5460
dclTextOr(tree) {

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
654654

655655
val bodyText = "{" ~~ selfText ~~ toTextGlobal(primaryConstrs ::: body, "\n") ~ "}"
656656

657-
prefix ~ (keywordText(" extends") provided !ofNew) ~~ parentsText ~~ bodyText
657+
prefix ~ (keywordText(" extends") provided (!ofNew && parents.nonEmpty)) ~~ parentsText ~~ bodyText
658658
}
659659

660660
protected def templateText(tree: TypeDef, impl: Template): Text = {

tests/pos/lambda.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
out/posTestFromTasty/pos/lambda/foo/Foo.class
33
--------------------------------------------------------------------------------
44
package foo {
5-
class Foo() extends Object() {
5+
class Foo() {
66
val a: Int => Int =
77
{
88
(x: Int) => x.*(x)

tests/pos/methodTypes.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
================================================================================
22
out/posTestFromTasty/pos/methodTypes/Foo.class
33
--------------------------------------------------------------------------------
4-
class Foo() extends Object() {
4+
class Foo() {
55
val x: Int = 1
66
def y: Int = 2
77
def z(): Int = 3

tests/pos/simpleCaseObject.decompiled

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
out/posTestFromTasty/pos/simpleCaseObject/foo/Foo.class
33
--------------------------------------------------------------------------------
44
package foo {
5-
case object Foo() extends Object() with _root_.scala.Product {
6-
this: foo.Foo.type =>
7-
5+
case object Foo() extends _root_.scala.Product { this: foo.Foo.type =>
86
override def hashCode(): Int = 1045991777
97
override def toString(): String = "Foo"
108
override def canEqual(that: Any): Boolean = that.isInstanceOf[foo.Foo]

tests/pos/simpleClass-2.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ package foo {
99
out/posTestFromTasty/pos/simpleClass-2/foo/B.class
1010
--------------------------------------------------------------------------------
1111
package foo {
12-
class B() extends Object() {}
12+
class B() {}
1313
}
1414
--------------------------------------------------------------------------------

tests/pos/simpleClass.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
out/posTestFromTasty/pos/simpleClass/foo/A.class
33
--------------------------------------------------------------------------------
44
package foo {
5-
class A() extends Object() {}
5+
class A() {}
66
}
77
--------------------------------------------------------------------------------
88
================================================================================

tests/pos/simpleDoWhile.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
================================================================================
22
out/posTestFromTasty/pos/simpleDoWhile/Foo.class
33
--------------------------------------------------------------------------------
4-
class Foo() extends Object() {
4+
class Foo() {
55
def foo: Unit =
66
{
77
var i: Int = 1

tests/pos/simpleWhile.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
================================================================================
22
out/posTestFromTasty/pos/simpleWhile/Foo.class
33
--------------------------------------------------------------------------------
4-
class Foo() extends Object() {
4+
class Foo() {
55
def foo: Unit =
66
{
77
var i: Int = 1

tests/run/puzzle.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
================================================================================
22
out/runTestFromTasty/run/puzzle/Test.class
33
--------------------------------------------------------------------------------
4-
object Test() extends Object() { this: Test.type =>
4+
object Test() { this: Test.type =>
55
def main(args: Array[String]): Unit =
66
{
77
println(if false then 5.0 else 53.0)

0 commit comments

Comments
 (0)