From db114aa44efe63763a883dcf07d667fe7d744ff6 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 26 May 2015 16:42:01 +1000 Subject: SI-7747 Limit previous change to imports of REPL vals We only need to introduce the temporary val in the imports wrapper when we are importing a val or module defined in the REPL. The test case from the previous commit still passes, but we are generating slightly simpler code. Compared to 2.11.6, these two commits result in the following diff: https://gist.github.com/retronym/aa4bd3aeef1ab1b85fe9 --- src/repl/scala/tools/nsc/interpreter/Imports.scala | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/repl/scala/tools/nsc/interpreter/Imports.scala b/src/repl/scala/tools/nsc/interpreter/Imports.scala index 97798cd017..c52869e208 100644 --- a/src/repl/scala/tools/nsc/interpreter/Imports.scala +++ b/src/repl/scala/tools/nsc/interpreter/Imports.scala @@ -165,12 +165,17 @@ trait Imports { case x if isClassBased => for (imv <- x.definedNames) { if (!currentImps.contains(imv)) { - val valName = req.lineRep.packageName + req.lineRep.readName - if (!tempValLines.contains(req.lineRep.lineId)) { - code.append(s"val $valName = $objName\n") - tempValLines += req.lineRep.lineId + x match { + case _: ValHandler | _: ModuleHandler => + val valName = req.lineRep.packageName + req.lineRep.readName + if (!tempValLines.contains(req.lineRep.lineId)) { + code.append(s"val $valName = $objName\n") + tempValLines += req.lineRep.lineId + } + code.append(s"import $valName ${req.accessPath}.`$imv`;\n") + case _ => + code.append("import " + objName + req.accessPath + ".`" + imv + "`\n") } - code.append(s"import $valName ${req.accessPath}.`$imv`;\n") currentImps += imv } } -- cgit v1.2.3