Skip to content

Commit 11b8ee8

Browse files
committed
Print type of module class C as "object C"
1 parent 2a91274 commit 11b8ee8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,13 @@ object Formatting {
128128
}
129129

130130
private class ExplainingPrinter(seen: Seen)(_ctx: Context) extends RefinedPrinter(_ctx) {
131+
132+
/** True if printer should a source module instead of its module class */
133+
private def useSourceModule(sym: Symbol): Boolean =
134+
sym.is(ModuleClass, butNot = Package) && sym.sourceModule.exists && !_ctx.settings.YdebugNames.value
135+
131136
override def simpleNameString(sym: Symbol): String =
132-
if ((sym is ModuleClass) && sym.sourceModule.exists) simpleNameString(sym.sourceModule)
137+
if (useSourceModule(sym)) simpleNameString(sym.sourceModule)
133138
else seen.record(super.simpleNameString(sym), sym)
134139

135140
override def ParamRefNameString(param: ParamRef): String =
@@ -139,6 +144,11 @@ object Formatting {
139144
case tp: SkolemType => seen.record(tp.repr.toString, tp)
140145
case _ => super.toTextRef(tp)
141146
}
147+
148+
override def toText(tp: Type): Text = tp match {
149+
case tp: TypeRef if useSourceModule(tp.symbol) => Str("object ") ~ super.toText(tp)
150+
case _ => super.toText(tp)
151+
}
142152
}
143153

144154
/** Create explanation for single `Recorded` type or symbol */

0 commit comments

Comments
 (0)