diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2016-08-01 03:40:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-01 03:40:06 -0700 |
commit | 765aecbe3ca4e05c987dde4e868dca08c7585666 (patch) | |
tree | 946563d3e2a64d729060b5a3ea4d75f85ff1d482 | |
parent | a0ad3f1d020cc3f3f37bc887874517ace670bf52 (diff) | |
parent | 6fc81930c1014638fd7eeba026b8317e8bf5fc32 (diff) | |
download | dotty-765aecbe3ca4e05c987dde4e868dca08c7585666.tar.gz dotty-765aecbe3ca4e05c987dde4e868dca08c7585666.tar.bz2 dotty-765aecbe3ca4e05c987dde4e868dca08c7585666.zip |
Merge pull request #1429 from dotty-staging/fix-#1426
Fix #1426: Fix varable printing in REPL
-rw-r--r-- | src/dotty/tools/dotc/repl/CompilingInterpreter.scala | 10 | ||||
-rw-r--r-- | tests/repl/vars.check | 8 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala index 9750c9039..e05ecb328 100644 --- a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala +++ b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala @@ -363,7 +363,7 @@ class CompilingInterpreter( private def objectSourceCode: String = stringFrom { code => // header for the wrapper object - code.println("object " + objectName + " {") + code.println(s"object $objectName{") code.print(importsPreamble) code.println(toCompute) handlers.foreach(_.extraCodeToEvaluate(this,code)) @@ -380,9 +380,9 @@ class CompilingInterpreter( from objectSourceCode */ private def resultObjectSourceCode: String = stringFrom(code => { - code.println("object " + resultObjectName) + code.println(s"object $resultObjectName") code.println("{ val result: String = {") - code.println(objectName + accessPath + ";") // evaluate the object, to make sure its constructor is run + code.println(s"$objectName$accessPath;") // evaluate the object, to make sure its constructor is run code.print("(\"\"") // print an initial empty string, so later code can // uniformly be: + morestuff handlers.foreach(_.resultExtractionCode(this, code)) @@ -705,12 +705,12 @@ class CompilingInterpreter( override val valAndVarNames = List(helperName) override def extraCodeToEvaluate(req: Request, code: PrintWriter): Unit = { - code.println("val " + helperName + " = " + statement.lhs + ";") + code.println(i"val $helperName = ${statement.lhs};") } /** Print out lhs instead of the generated varName */ override def resultExtractionCode(req: Request, code: PrintWriter): Unit = { - code.print(" + \"" + lhs + ": " + + code.print(" + \"" + lhs.show + ": " + string2code(req.typeOf(helperName.encode)) + " = \" + " + string2code(req.fullPath(helperName)) diff --git a/tests/repl/vars.check b/tests/repl/vars.check new file mode 100644 index 000000000..5cebbf61c --- /dev/null +++ b/tests/repl/vars.check @@ -0,0 +1,8 @@ +scala> var x = 0 +x: Int = 0 +scala> x = x + 1 +x: Int = 1 +scala> x *= 2 +scala> x +res2: Int = 2 +scala> :quit |