diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-11-24 15:04:18 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-11-24 15:04:18 +0100 |
commit | 08e17339a36a8dddb65c35a23fa045d4af1b67b1 (patch) | |
tree | a5f7c6270bdd83b4f1724d58def59dae2d9a7185 /compiler | |
parent | b33c962f23eb6abc2708184a6a344485c24c444d (diff) | |
download | dotty-08e17339a36a8dddb65c35a23fa045d4af1b67b1.tar.gz dotty-08e17339a36a8dddb65c35a23fa045d4af1b67b1.tar.bz2 dotty-08e17339a36a8dddb65c35a23fa045d4af1b67b1.zip |
Fix defs not being printed correctly
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala index 84b7199f4..00f24845e 100644 --- a/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala +++ b/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala @@ -740,9 +740,28 @@ class CompilingInterpreter( override def defNames = boundNames override def resultExtractionCode(req: Request, code: PrintWriter): Unit = { - if (!defDef.mods.is(Flags.AccessFlags)) - code.print("+\"def " + string2code(defDef.name.toString) + - string2code(req.typeOf(defDef.name)) + "\\n\"") + /** TODO: This is the result of the state of the REPL - this would be + * entirely unnecessary with a better structure where we could just + * use the type printer + * + * @see `def findTypes` for an explanation of what should be done + */ + if (!defDef.mods.is(Flags.AccessFlags)) { + val tpt = defDef.tpt match { + // ascribed TypeExpr e.g: `def foo: Int = 5` + case Ident(tpt) if defDef.vparamss.isEmpty => + ": " + tpt.show + // inferred TypeExpr e.g: `def foo = 5` + case tpt if defDef.vparamss.isEmpty => + ": " + req.typeOf(defDef.name) + // Inferred or ascribed MethodType with parameter list + case _ => + req.typeOf(defDef.name) + } + code.print { + "+\"def " + string2code(defDef.name.toString) + tpt + "\\n\"" + } + } } } |