From ccc671bed8ee57542652e5c79ef556452784b2cd Mon Sep 17 00:00:00 2001 From: Reto Hablützel Date: Tue, 15 Nov 2016 07:06:17 +0100 Subject: Add colon after method type, prefix def/val/var in REPL --- compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala | 6 +++++- compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala | 9 +++++++-- 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 { "" 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\"") } } -- cgit v1.2.3