aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-03-06 16:49:00 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-03-18 11:14:15 +0100
commit073449ef52b344e00cf1b19b55676c6a6a4452a6 (patch)
tree35a8cc316804b260bb68d7ef05c41a69e62d5183 /src
parentc6bba9b9b63da5b28fd70409366c191cec5d2acb (diff)
downloaddotty-073449ef52b344e00cf1b19b55676c6a6a4452a6.tar.gz
dotty-073449ef52b344e00cf1b19b55676c6a6a4452a6.tar.bz2
dotty-073449ef52b344e00cf1b19b55676c6a6a4452a6.zip
Systematic treatement of homogenized views in printing
A homogenized view makes sure that there are no spurious differences between trees before and after pickling. Currently there are two cases where homogenized is different from standard view: 1) Backquoted idents are not printed in backticks 2) Instantiated TypeVars so not get an apostroph.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/printing/PlainPrinter.scala13
-rw-r--r--src/dotty/tools/dotc/printing/RefinedPrinter.scala6
2 files changed, 13 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala
index 0bd1d4499..0fd862afb 100644
--- a/src/dotty/tools/dotc/printing/PlainPrinter.scala
+++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala
@@ -33,6 +33,14 @@ class PlainPrinter(_ctx: Context) extends Printer {
ctx.warning("Exceeded recursion depth attempting to print.")
(new Throwable).printStackTrace
}
+
+ /** If true, tweak output so it is the same before and after pickling */
+ protected def homogenizedView: Boolean = ctx.settings.YtestPickler.value
+
+ def homogenize(tp: Type): Type = tp match {
+ case tp: TypeVar if homogenizedView && tp.isInstantiated => homogenize(tp.instanceOpt)
+ case _ => tp
+ }
/** Render elements alternating with `sep` string */
protected def toText(elems: Traversable[Showable], sep: String) =
@@ -91,7 +99,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
})
def toText(tp: Type): Text = controlled {
- tp match {
+ homogenize(tp) match {
case tp: TypeType =>
toTextRHS(tp)
case tp: TermRef if !tp.denotationIsCurrent || tp.symbol.is(Module) =>
@@ -141,8 +149,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
toTextLocal(tpe) ~ " " ~ toText(annot)
case tp: TypeVar =>
if (tp.isInstantiated)
- if (ctx.settings.YtestPickler.value) toText(tp.instanceOpt)
- else toTextLocal(tp.instanceOpt) // debug for now, so that we can see where the TypeVars are.
+ toTextLocal(tp.instanceOpt) ~ "'" // debug for now, so that we can see where the TypeVars are.
else {
val constr = ctx.typerState.constraint
val bounds =
diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
index fa2ba6586..bbe958241 100644
--- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala
+++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
@@ -104,7 +104,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
toTextTuple(args.init)
argStr ~ " => " ~ toText(args.last)
}
- tp match {
+ homogenize(tp) match {
case tp: RefinedType =>
val args = tp.argInfos(interpolate = false)
if (args.nonEmpty) {
@@ -137,7 +137,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
return "?{ " ~ toText(tp.name) ~ ": " ~ toText(tp.memberProto) ~ " }"
case tp: ViewProto =>
return toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType)
- case FunProto(args, resultType, _) =>
+ case tp @ FunProto(args, resultType, _) =>
val argsText = args match {
case dummyTreeOfType(tp) :: Nil if !(tp isRef defn.NullClass) => "null: " ~ toText(tp)
case _ => toTextGlobal(args, ", ")
@@ -252,7 +252,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
}
var txt: Text = tree match {
- case id: Trees.BackquotedIdent[_] =>
+ case id: Trees.BackquotedIdent[_] if !homogenizedView =>
"`" ~ toText(id.name) ~ "`"
case Ident(name) =>
tree.typeOpt match {