diff options
author | Martin Odersky <odersky@gmail.com> | 2015-03-08 15:27:45 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-03-18 11:16:36 +0100 |
commit | 31a90b4e882dcbae333975d72f50820afbcf5c95 (patch) | |
tree | 9fb61dbc89de5e3b49f8169e00f1e9e2ba8fbf3b /src | |
parent | bb5762a056c3d2ee224cea0f01726d8900745366 (diff) | |
download | dotty-31a90b4e882dcbae333975d72f50820afbcf5c95.tar.gz dotty-31a90b4e882dcbae333975d72f50820afbcf5c95.tar.bz2 dotty-31a90b4e882dcbae333975d72f50820afbcf5c95.zip |
Homogenize package ids and literals
The unpickled term in a package id is different from the original but the
type is the same.
In a literal prefer constants in the types over thsoe in the terms.
With this change, we get identical typed tree output also for core/pickled.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/printing/RefinedPrinter.scala | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 9b2d30fdf..dcbf92cfe 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -252,6 +252,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { prefix ~ (" extends" provided !ofNew) ~~ parentsText ~~ bodyText } + def toTextPackageId(pid: Tree): Text = + if (homogenizedView) toTextLocal(pid.tpe) + else toTextLocal(pid) + var txt: Text = tree match { case id: Trees.BackquotedIdent[_] if !homogenizedView => "`" ~ toText(id.name) ~ "`" @@ -282,7 +286,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case TypeApply(fun, args) => toTextLocal(fun) ~ "[" ~ toTextGlobal(args, ", ") ~ "]" case Literal(c) => - toText(c) + tree.typeOpt match { + case ConstantType(tc) => toText(tc) + case _ => toText(c) + } case New(tpt) => "new " ~ { tpt match { @@ -404,7 +411,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } val bodyText = if (currentPrecedence == TopLevelPrec) "\n" ~ statsText else " {" ~ statsText ~ "}" - "package " ~ toTextLocal(pid) ~ bodyText + "package " ~ toTextPackageId(pid) ~ bodyText case tree: Template => toTextTemplate(tree) case Annotated(annot, arg) => @@ -509,7 +516,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { def optText[T >: Untyped](tree: List[Tree[T]])(encl: Text => Text): Text = if (tree.exists(!_.isEmpty)) encl(blockText(tree)) else "" - + override protected def polyParamName(name: TypeName): TypeName = name.unexpandedName |