Skip to content

Commit fc03114

Browse files
authored
Merge pull request #1627 from dotty-staging/prettyprint
fix #1626: inconsistent names in prettyprint
2 parents ea70ff8 + 485df22 commit fc03114

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import reporting.Reporter
1515
import transform.TreeChecker
1616
import rewrite.Rewrites
1717
import java.io.{BufferedWriter, OutputStreamWriter}
18+
import printing.XprintMode
1819

1920
import scala.annotation.tailrec
2021
import scala.reflect.io.VirtualFile
@@ -95,7 +96,7 @@ class Run(comp: Compiler)(implicit ctx: Context) {
9596
val unit = ctx.compilationUnit
9697
val prevPhase = ctx.phase.prev // can be a mini-phase
9798
val squashedPhase = ctx.squashed(prevPhase)
98-
val treeString = unit.tpdTree.show
99+
val treeString = unit.tpdTree.show(ctx.withProperty(XprintMode, Some(())))
99100

100101
ctx.echo(s"result of $unit after $squashedPhase:")
101102

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
6161
override def nameString(name: Name): String = name.decode.toString
6262

6363
override protected def simpleNameString(sym: Symbol): String = {
64-
val name = sym.originalName
64+
val name = if (ctx.property(XprintMode).isEmpty) sym.originalName else sym.name
6565
nameString(if (sym is ExpandedTypeParam) name.asTypeName.unexpandedName else name)
6666
}
6767

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dotty.tools.dotc
22

33
import core.StdNames.nme
44
import parsing.{precedence, minPrec, maxPrec, minInfixPrec}
5+
import util.Property.Key
56

67
package object printing {
78

@@ -14,4 +15,9 @@ package object printing {
1415
val GlobalPrec = parsing.minPrec
1516
val TopLevelPrec = parsing.minPrec - 1
1617

18+
/** A property to indicate whether the compiler is currently doing -Xprint
19+
*
20+
* -Xprint will print `sym.name` instead of `sym.originalName`
21+
*/
22+
val XprintMode = new Key[Unit]
1723
}

0 commit comments

Comments
 (0)