Skip to content

Commit 11fe1b9

Browse files
committed
Override printing of self in DecompilerPrinter
1 parent c1d1c21 commit 11fe1b9

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
5454
decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~ ""
5555
}
5656

57+
override protected def selfToText(impl: Template): Text =
58+
super.selfToText(impl).provided(!impl.constr.symbol.owner.is(Module))
59+
5760
override protected def toTextTemplate(impl: Template, ofNew: Boolean = false): Text = {
5861
def isSyntheticParent(sym: Symbol): Boolean = {
5962
sym.maybeOwner == defn.ObjectClass ||

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
649649
withEnclosingDef(constr) { addVparamssText(tparamsTxt ~~ modsText, vparamss) }
650650
}
651651
val parentsText = Text(parents map constrText, keywordStr(" with "))
652-
val selfText = {
653-
val selfName = if (self.name == nme.WILDCARD) keywordStr("this") else self.name.toString
654-
(selfName ~ optText(self.tpt)(": " ~ _) ~ " =>").close
655-
} provided (!self.isEmpty && !constr.symbol.owner.is(Module))
656-
652+
val selfText = selfToText(impl)
657653
val body = if (ctx.settings.YtestPickler.value) {
658654
// Pickling/unpickling reorders the body members, so we need to homogenize
659655
val (params, rest) = impl.body partition {
@@ -670,6 +666,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
670666
prefix ~ (keywordText(" extends") provided (!ofNew && parents.nonEmpty)) ~~ parentsText ~~ bodyText
671667
}
672668

669+
protected def selfToText(impl: Template): Text = {
670+
val self = impl.self
671+
val selfName = if (self.name == nme.WILDCARD) keywordStr("this") else self.name.toString
672+
(selfName ~ optText(self.tpt)(": " ~ _) ~ " =>").close provided (!self.isEmpty)
673+
}
674+
673675
protected def templateText(tree: TypeDef, impl: Template): Text = {
674676
val decl = modText(tree.mods, keywordStr(if ((tree).mods is Trait) "trait" else "class"))
675677
decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~

0 commit comments

Comments
 (0)