Skip to content

Commit c52ffd7

Browse files
committed
Make findTypes take the resultType of MethodType
This is done so that we can use show for the entire method except for the ascribed type added by the compiler on success.
1 parent 08e1733 commit c52ffd7

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
164164
"<noprefix>"
165165
case tp: MethodType =>
166166
def paramText(name: TermName, tp: Type) = toText(name) ~ ": " ~ toText(tp)
167-
def typeColon(resultType: Type): Text = resultType match {
168-
case _: TypeRef => ": "
169-
case _ => "" // eg. methods with implicit parameters go here in first pass
170-
}
171167
changePrec(GlobalPrec) {
172168
(if (tp.isImplicit) "(implicit " else "(") ~
173169
Text((tp.paramNames, tp.paramTypes).zipped map paramText, ", ") ~
174-
")" ~ typeColon(tp.resultType) ~ toText(tp.resultType)
170+
")" ~ toText(tp.resultType)
175171
}
176172
case tp: ExprType =>
177173
changePrec(GlobalPrec) { "=> " ~ toText(tp.resultType) }

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ class CompilingInterpreter(
443443
}
444444

445445
// the types are all =>T; remove the =>
446-
val cleanedType = rawType.widenExpr
446+
val cleanedType = rawType.widenExpr match {
447+
case tp: MethodType => tp.resultType
448+
case tp => tp
449+
}
447450

448451
map + (name ->
449452
ctx.atPhase(ctx.typerPhase.next) { implicit ctx =>
@@ -747,19 +750,21 @@ class CompilingInterpreter(
747750
* @see `def findTypes` for an explanation of what should be done
748751
*/
749752
if (!defDef.mods.is(Flags.AccessFlags)) {
753+
// Take the DefDef and remove the `rhs` and ascribed type `tpt`
754+
val copy = ast.untpd.cpy.DefDef(defDef)(
755+
rhs = EmptyTree,
756+
tpt = TypeTree
757+
)
758+
750759
val tpt = defDef.tpt match {
751760
// ascribed TypeExpr e.g: `def foo: Int = 5`
752761
case Ident(tpt) if defDef.vparamss.isEmpty =>
753762
": " + tpt.show
754-
// inferred TypeExpr e.g: `def foo = 5`
755-
case tpt if defDef.vparamss.isEmpty =>
763+
case tpt =>
756764
": " + req.typeOf(defDef.name)
757-
// Inferred or ascribed MethodType with parameter list
758-
case _ =>
759-
req.typeOf(defDef.name)
760765
}
761766
code.print {
762-
"+\"def " + string2code(defDef.name.toString) + tpt + "\\n\""
767+
"+\"" + string2code(copy.show) + tpt + "\\n\""
763768
}
764769
}
765770
}

0 commit comments

Comments
 (0)