Skip to content

Commit

Permalink
Merge pull request #4731 from dotty-staging/package-object
Browse files Browse the repository at this point in the history
Fix printing of package object symbol
  • Loading branch information
allanrenucci authored Jul 3, 2018
2 parents 264cbf8 + 107d8ff commit a6b6690
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
27 changes: 27 additions & 0 deletions compiler/test/dotty/tools/dotc/printing/PrinterTests.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit a6b6690

Please sign in to comment.