Skip to content

Commit dbefc2a

Browse files
author
Reto Hablützel
committed
Add colon after method type, prefix def/val/var in REPL
1 parent 601a286 commit dbefc2a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,14 @@ class PlainPrinter(_ctx: Context) extends Printer {
159159
"<noprefix>"
160160
case tp: MethodType =>
161161
def paramText(name: TermName, tp: Type) = toText(name) ~ ": " ~ toText(tp)
162+
def typeColon(resultType: Type): Text = resultType match {
163+
case _: TypeRef => ": "
164+
case _ => "" // eg. methods with implicit parameters go here in first pass
165+
}
162166
changePrec(GlobalPrec) {
163167
(if (tp.isImplicit) "(implicit " else "(") ~
164168
Text((tp.paramNames, tp.paramTypes).zipped map paramText, ", ") ~
165-
")" ~ toText(tp.resultType)
169+
")" ~ typeColon(tp.resultType) ~ toText(tp.resultType)
166170
}
167171
case tp: ExprType =>
168172
changePrec(GlobalPrec) { "=> " ~ toText(tp.resultType) }

src/dotty/tools/dotc/repl/CompilingInterpreter.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,12 @@ class CompilingInterpreter(
685685
val varType = string2code(req.typeOf(varName))
686686
val fullPath = req.fullPath(varName)
687687

688-
s""" + "$prettyName: $varType = " + {
688+
val varOrVal = statement match {
689+
case v: ValDef if v.mods is Flags.Mutable => "var"
690+
case _ => "val"
691+
}
692+
693+
s""" + "$varOrVal $prettyName: $varType = " + {
689694
| if ($fullPath.asInstanceOf[AnyRef] != null) {
690695
| (if ($fullPath.toString().contains('\\n')) "\\n" else "") +
691696
| $fullPath.toString() + "\\n"
@@ -736,7 +741,7 @@ class CompilingInterpreter(
736741

737742
override def resultExtractionCode(req: Request, code: PrintWriter): Unit = {
738743
if (!defDef.mods.is(Flags.AccessFlags))
739-
code.print("+\"" + string2code(defDef.name.toString) + ": " +
744+
code.print("+\"def " + string2code(defDef.name.toString) +
740745
string2code(req.typeOf(defDef.name)) + "\\n\"")
741746
}
742747
}

0 commit comments

Comments
 (0)