summaryrefslogtreecommitdiff
path: root/src/repl
diff options
context:
space:
mode:
authorAntoine Gourlay <antoine@gourlay.fr>2013-08-16 17:22:18 +0200
committerAntoine Gourlay <antoine@gourlay.fr>2013-08-16 17:22:18 +0200
commit6db8a523e32c093c70b27797628bacbda78b81bb (patch)
tree496138c6840e8f999d02b6c11e05ef128b938fc0 /src/repl
parentf17fb5eaa545490c761acd4f6979a619f919ac86 (diff)
downloadscala-6db8a523e32c093c70b27797628bacbda78b81bb.tar.gz
scala-6db8a523e32c093c70b27797628bacbda78b81bb.tar.bz2
scala-6db8a523e32c093c70b27797628bacbda78b81bb.zip
SI-6507 do not call .toString on REPL results when :silent is on.
Member handlers used to always call .toString on REPL results, even when :silent was on, which could force evaluation or cause unwanted side effects. This forwards the current value of `printResults` to the member handlers (through Request) for them to decide what to do when the results must not be printed. 2 handlers now do not return any extraction code when silent: - ValHandler, so that it doesn't call toString on the val - Assign, so that it doesn't call toString on the right-hand side of the assignement.
Diffstat (limited to 'src/repl')
-rw-r--r--src/repl/scala/tools/nsc/interpreter/IMain.scala2
-rw-r--r--src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala6
2 files changed, 5 insertions, 3 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala
index 3a71930383..b35f71aeef 100644
--- a/src/repl/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala
@@ -838,6 +838,8 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
def imports = importedSymbols
def value = Some(handlers.last) filter (h => h.definesValue) map (h => definedSymbols(h.definesTerm.get)) getOrElse NoSymbol
+ val printResults = IMain.this.printResults
+
val lineRep = new ReadEvalPrint()
private var _originalLine: String = null
diff --git a/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala b/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala
index c6f0cca481..085a7c6065 100644
--- a/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala
+++ b/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala
@@ -107,7 +107,7 @@ trait MemberHandlers {
override def resultExtractionCode(req: Request): String = {
val isInternal = isUserVarName(name) && req.lookupTypeOf(name) == "Unit"
- if (!mods.isPublic || isInternal) ""
+ if (!mods.isPublic || isInternal || !req.printResults) ""
else {
// if this is a lazy val we avoid evaluating it here
val resultString =
@@ -151,11 +151,11 @@ trait MemberHandlers {
"""val %s = %s""".format(name, lhs)
/** Print out lhs instead of the generated varName */
- override def resultExtractionCode(req: Request) = {
+ override def resultExtractionCode(req: Request) = if (req.printResults) {
val lhsType = string2code(req lookupTypeOf name)
val res = string2code(req fullPath name)
""" + "%s: %s = " + %s + "\n" """.format(string2code(lhs.toString), lhsType, res) + "\n"
- }
+ } else ""
}
class ModuleHandler(module: ModuleDef) extends MemberDefHandler(module) {