Skip to content

Commit a6b6690

Browse files
authored
Merge pull request #4731 from dotty-staging/package-object
Fix printing of package object symbol
2 parents 264cbf8 + 107d8ff commit a6b6690

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
745745
case info: ImportType => return s"import $info.expr.show"
746746
case _ =>
747747
}
748-
if (sym.is(ModuleClass))
749-
kindString(sym) ~~ (nameString(sym.name.stripModuleClassSuffix) + idString(sym))
748+
if (sym.is(ModuleClass)) {
749+
val name =
750+
if (sym.isPackageObject) sym.owner.name
751+
else sym.name.stripModuleClassSuffix
752+
kindString(sym) ~~ (nameString(name) + idString(sym))
753+
}
750754
else
751755
super.toText(sym)
752756
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package dotty.tools.dotc.printing
2+
3+
import dotty.tools.DottyTest
4+
import dotty.tools.dotc.ast.tpd
5+
import dotty.tools.dotc.core.Names._
6+
import dotty.tools.dotc.core.Symbols._
7+
import org.junit.Assert.assertEquals
8+
import org.junit.Test
9+
10+
class PrinterTests extends DottyTest {
11+
import tpd._
12+
13+
@Test
14+
def packageObject: Unit = {
15+
val source = """
16+
package object foo {
17+
def bar: Int = 1
18+
}
19+
"""
20+
21+
checkCompile("frontend", source) { (tree, context) =>
22+
implicit val ctx = context
23+
val bar = tree.find(tree => tree.symbol.name == termName("bar")).get
24+
assertEquals("package object foo", bar.symbol.owner.show)
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)