aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReto Hablützel <rh@nezasa.com>2016-11-15 07:06:17 +0100
committerFelix Mulder <felix.mulder@gmail.com>2016-11-24 13:11:15 +0100
commitccc671bed8ee57542652e5c79ef556452784b2cd (patch)
tree2879cc200be9fc7336b834430d3dfa7184594d5f
parent3599c243c86ae0a926ef45a435d38b7878dc322f (diff)
downloaddotty-ccc671bed8ee57542652e5c79ef556452784b2cd.tar.gz
dotty-ccc671bed8ee57542652e5c79ef556452784b2cd.tar.bz2
dotty-ccc671bed8ee57542652e5c79ef556452784b2cd.zip
Add colon after method type, prefix def/val/var in REPL
-rw-r--r--compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala6
-rw-r--r--compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala9
2 files changed, 12 insertions, 3 deletions
diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
index 15c382bb0..8745cb320 100644
--- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
+++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
@@ -164,10 +164,14 @@ class PlainPrinter(_ctx: Context) extends Printer {
"<noprefix>"
case tp: MethodType =>
def paramText(name: TermName, tp: Type) = toText(name) ~ ": " ~ toText(tp)
+ def typeColon(resultType: Type): Text = resultType match {
+ case _: TypeRef => ": "
+ case _ => "" // eg. methods with implicit parameters go here in first pass
+ }
changePrec(GlobalPrec) {
(if (tp.isImplicit) "(implicit " else "(") ~
Text((tp.paramNames, tp.paramTypes).zipped map paramText, ", ") ~
- ")" ~ toText(tp.resultType)
+ ")" ~ typeColon(tp.resultType) ~ toText(tp.resultType)
}
case tp: ExprType =>
changePrec(GlobalPrec) { "=> " ~ toText(tp.resultType) }
diff --git a/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
index 5b3669d5e..84b7199f4 100644
--- a/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
+++ b/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
@@ -685,7 +685,12 @@ class CompilingInterpreter(
val varType = string2code(req.typeOf(varName))
val fullPath = req.fullPath(varName)
- s""" + "$prettyName: $varType = " + {
+ val varOrVal = statement match {
+ case v: ValDef if v.mods is Flags.Mutable => "var"
+ case _ => "val"
+ }
+
+ s""" + "$varOrVal $prettyName: $varType = " + {
| if ($fullPath.asInstanceOf[AnyRef] != null) {
| (if ($fullPath.toString().contains('\\n')) "\\n" else "") +
| $fullPath.toString() + "\\n"
@@ -736,7 +741,7 @@ class CompilingInterpreter(
override def resultExtractionCode(req: Request, code: PrintWriter): Unit = {
if (!defDef.mods.is(Flags.AccessFlags))
- code.print("+\"" + string2code(defDef.name.toString) + ": " +
+ code.print("+\"def " + string2code(defDef.name.toString) +
string2code(req.typeOf(defDef.name)) + "\\n\"")
}
}