diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-12-14 16:40:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-14 16:40:31 +0100 |
commit | ba06bf06721f1a8de7d68d22ad7eba27fff90c43 (patch) | |
tree | a02167f1d4d786c027c600c0070c36055cbc2622 /compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala | |
parent | 19bc03c840f0d6f0678775625562cea5ad7193e7 (diff) | |
parent | 35e8fcb805e7780555cf48160f90c9da71bb1811 (diff) | |
download | dotty-ba06bf06721f1a8de7d68d22ad7eba27fff90c43.tar.gz dotty-ba06bf06721f1a8de7d68d22ad7eba27fff90c43.tar.bz2 dotty-ba06bf06721f1a8de7d68d22ad7eba27fff90c43.zip |
Merge pull request #1761 from dotty-staging/topic/product-show
[REPL] Add show capability to common types
Diffstat (limited to 'compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala')
-rw-r--r-- | compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala index d849ea370..65c64f708 100644 --- a/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala +++ b/compiler/src/dotty/tools/dotc/repl/CompilingInterpreter.scala @@ -683,9 +683,36 @@ class CompilingInterpreter( code.print(resultExtractors.mkString("")) } + private val ListReg = """^.*List\[(\w+)\]$""".r + private val MapReg = """^.*Map\[(\w+),[ ]*(\w+)\]$""".r + private val LitReg = """^.*\((.+)\)$""".r + private def resultExtractor(req: Request, varName: Name): String = { val prettyName = varName.decode - val varType = string2code(req.typeOf(varName)) + // FIXME: `varType` is prettified to abbreviate common types where + // appropriate, and to also prettify literal types + // + // This should be rewritten to use the actual types once we have a + // semantic representation available to the REPL + val varType = string2code(req.typeOf(varName)) match { + // Extract List's paremeter from full path + case ListReg(param) => s"List[$param]" + // Extract Map's paremeters from full path + case MapReg(k, v) => s"Map[$k, $v]" + // Extract literal type from literal type representation. Example: + // + // ``` + // scala> val x: 42 = 42 + // val x: Int(42) = 42 + // scala> val y: "hello" = "hello" + // val y: String("hello") = "hello" + // ``` + case LitReg(lit) => lit + // When the type is a singleton value like None, don't show `None$` + // instead show `None.type`. + case x if x.lastOption == Some('$') => x.init + ".type" + case x => x + } val fullPath = req.fullPath(varName) val varOrVal = statement match { @@ -695,8 +722,10 @@ class CompilingInterpreter( s""" + "$varOrVal $prettyName: $varType = " + { | if ($fullPath.asInstanceOf[AnyRef] != null) { - | (if ($fullPath.toString().contains('\\n')) "\\n" else "") + - | $fullPath.toString() + "\\n" + | (if ($fullPath.toString().contains('\\n')) "\\n" else "") + { + | import dotty.Show._ + | $fullPath.show /*toString()*/ + "\\n" + | } | } else { | "null\\n" | } |