aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-24 15:04:18 +0100
committerFelix Mulder <felix.mulder@gmail.com>2016-11-24 15:04:18 +0100
commit08e17339a36a8dddb65c35a23fa045d4af1b67b1 (patch)
treea5f7c6270bdd83b4f1724d58def59dae2d9a7185 /compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
parentb33c962f23eb6abc2708184a6a344485c24c444d (diff)
downloaddotty-08e17339a36a8dddb65c35a23fa045d4af1b67b1.tar.gz
dotty-08e17339a36a8dddb65c35a23fa045d4af1b67b1.tar.bz2
dotty-08e17339a36a8dddb65c35a23fa045d4af1b67b1.zip
Fix defs not being printed correctly
Diffstat (limited to 'compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala25
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\""
+ }
+ }
}
}