Skip to content

Add colon after method type in printer #1705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,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) }
Expand Down
9 changes: 7 additions & 2 deletions src/dotty/tools/dotc/repl/CompilingInterpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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\"")
}
}
Expand Down