From f7bf2b43745df51f908f17bce5de13625eba355c Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Wed, 27 Jun 2018 18:16:46 +0200 Subject: [PATCH 1/2] Fix printing of package object symbol --- .../src/dotty/tools/dotc/printing/RefinedPrinter.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index f1cf87ad9c1f..b64ec3a5ad92 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -745,8 +745,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case info: ImportType => return s"import $info.expr.show" case _ => } - if (sym.is(ModuleClass)) - kindString(sym) ~~ (nameString(sym.name.stripModuleClassSuffix) + idString(sym)) + if (sym.is(ModuleClass)) { + val name = + if (sym.isPackageObject) sym.owner.name + else sym.name.stripModuleClassSuffix + kindString(sym) ~~ (nameString(name) + idString(sym)) + } else super.toText(sym) } From 107d8ff4906ecee3861654ed5f473c39221b57ba Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Tue, 3 Jul 2018 14:37:52 +0200 Subject: [PATCH 2/2] Add printer tests --- .../tools/dotc/printing/PrinterTests.scala | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 compiler/test/dotty/tools/dotc/printing/PrinterTests.scala diff --git a/compiler/test/dotty/tools/dotc/printing/PrinterTests.scala b/compiler/test/dotty/tools/dotc/printing/PrinterTests.scala new file mode 100644 index 000000000000..629f8529a143 --- /dev/null +++ b/compiler/test/dotty/tools/dotc/printing/PrinterTests.scala @@ -0,0 +1,27 @@ +package dotty.tools.dotc.printing + +import dotty.tools.DottyTest +import dotty.tools.dotc.ast.tpd +import dotty.tools.dotc.core.Names._ +import dotty.tools.dotc.core.Symbols._ +import org.junit.Assert.assertEquals +import org.junit.Test + +class PrinterTests extends DottyTest { + import tpd._ + + @Test + def packageObject: Unit = { + val source = """ + package object foo { + def bar: Int = 1 + } + """ + + checkCompile("frontend", source) { (tree, context) => + implicit val ctx = context + val bar = tree.find(tree => tree.symbol.name == termName("bar")).get + assertEquals("package object foo", bar.symbol.owner.show) + } + } +}