Skip to content

Commit b7c793f

Browse files
committed
Override printing of self in DecompilerPrinter
1 parent bd21a64 commit b7c793f

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
@@ -640,11 +640,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
640640
withEnclosingDef(constr) { addVparamssText(tparamsTxt ~~ modsText, vparamss) }
641641
}
642642
val parentsText = Text(parents map constrText, keywordStr(" with "))
643-
val selfText = {
644-
val selfName = if (self.name == nme.WILDCARD) keywordStr("this") else self.name.toString
645-
(selfName ~ optText(self.tpt)(": " ~ _) ~ " =>").close
646-
} provided (!self.isEmpty && !constr.symbol.owner.is(Module))
647-
643+
val selfText = selfToText(impl)
648644
val body = if (ctx.settings.YtestPickler.value) {
649645
// Pickling/unpickling reorders the body members, so we need to homogenize
650646
val (params, rest) = impl.body partition {
@@ -661,6 +657,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
661657
prefix ~ (keywordText(" extends") provided (!ofNew && parents.nonEmpty)) ~~ parentsText ~~ bodyText
662658
}
663659

660+
protected def selfToText(impl: Template): Text = {
661+
val self = impl.self
662+
val selfName = if (self.name == nme.WILDCARD) keywordStr("this") else self.name.toString
663+
(selfName ~ optText(self.tpt)(": " ~ _) ~ " =>").close provided (!self.isEmpty)
664+
}
665+
664666
protected def templateText(tree: TypeDef, impl: Template): Text = {
665667
val decl = modText(tree.mods, keywordStr(if ((tree).mods is Trait) "trait" else "class"))
666668
decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~

0 commit comments

Comments
 (0)