File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed
compiler/src/dotty/tools/dotc/repl Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -740,9 +740,28 @@ class CompilingInterpreter(
740
740
override def defNames = boundNames
741
741
742
742
override def resultExtractionCode (req : Request , code : PrintWriter ): Unit = {
743
- if (! defDef.mods.is(Flags .AccessFlags ))
744
- code.print(" +\" def " + string2code(defDef.name.toString) +
745
- string2code(req.typeOf(defDef.name)) + " \\ n\" " )
743
+ /** TODO: This is the result of the state of the REPL - this would be
744
+ * entirely unnecessary with a better structure where we could just
745
+ * use the type printer
746
+ *
747
+ * @see `def findTypes` for an explanation of what should be done
748
+ */
749
+ if (! defDef.mods.is(Flags .AccessFlags )) {
750
+ val tpt = defDef.tpt match {
751
+ // ascribed TypeExpr e.g: `def foo: Int = 5`
752
+ case Ident (tpt) if defDef.vparamss.isEmpty =>
753
+ " : " + tpt.show
754
+ // inferred TypeExpr e.g: `def foo = 5`
755
+ case tpt if defDef.vparamss.isEmpty =>
756
+ " : " + req.typeOf(defDef.name)
757
+ // Inferred or ascribed MethodType with parameter list
758
+ case _ =>
759
+ req.typeOf(defDef.name)
760
+ }
761
+ code.print {
762
+ " +\" def " + string2code(defDef.name.toString) + tpt + " \\ n\" "
763
+ }
764
+ }
746
765
}
747
766
}
748
767
Original file line number Diff line number Diff line change
1
+ scala> def foo = 5
2
+ def foo: Int
3
+ scala> def bar: String = "1"
4
+ def bar: String
5
+ scala> def baz() = 2
6
+ def baz(): Int
7
+ scala> def qux(): Int = 2
8
+ def qux(): Int
9
+ scala> :quit
You can’t perform that action at this time.
0 commit comments