Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit db114aa

Browse files
committed
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
1 parent a3bb887 commit db114aa

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/repl/scala/tools/nsc/interpreter/Imports.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,17 @@ trait Imports {
165165
case x if isClassBased =>
166166
for (imv <- x.definedNames) {
167167
if (!currentImps.contains(imv)) {
168-
val valName = req.lineRep.packageName + req.lineRep.readName
169-
if (!tempValLines.contains(req.lineRep.lineId)) {
170-
code.append(s"val $valName = $objName\n")
171-
tempValLines += req.lineRep.lineId
168+
x match {
169+
case _: ValHandler | _: ModuleHandler =>
170+
val valName = req.lineRep.packageName + req.lineRep.readName
171+
if (!tempValLines.contains(req.lineRep.lineId)) {
172+
code.append(s"val $valName = $objName\n")
173+
tempValLines += req.lineRep.lineId
174+
}
175+
code.append(s"import $valName ${req.accessPath}.`$imv`;\n")
176+
case _ =>
177+
code.append("import " + objName + req.accessPath + ".`" + imv + "`\n")
172178
}
173-
code.append(s"import $valName ${req.accessPath}.`$imv`;\n")
174179
currentImps += imv
175180
}
176181
}

test/files/run/t7747-repl.check

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,12 @@ class $read extends Serializable {
258258
super.<init>;
259259
()
260260
};
261-
val $line44$read = $line44.$read.INSTANCE;
262-
import $line44$read.$iw.$iw.BippyBups;
263-
import $line44$read.$iw.$iw.BippyBups;
264-
val $line45$read = $line45.$read.INSTANCE;
265-
import $line45$read.$iw.$iw.PuppyPups;
266-
import $line45$read.$iw.$iw.PuppyPups;
267-
val $line46$read = $line46.$read.INSTANCE;
268-
import $line46$read.$iw.$iw.Bingo;
269-
import $line46$read.$iw.$iw.Bingo;
261+
import $line44.$read.INSTANCE.$iw.$iw.BippyBups;
262+
import $line44.$read.INSTANCE.$iw.$iw.BippyBups;
263+
import $line45.$read.INSTANCE.$iw.$iw.PuppyPups;
264+
import $line45.$read.INSTANCE.$iw.$iw.PuppyPups;
265+
import $line46.$read.INSTANCE.$iw.$iw.Bingo;
266+
import $line46.$read.INSTANCE.$iw.$iw.Bingo;
270267
class $iw extends Serializable {
271268
def <init>() = {
272269
super.<init>;

0 commit comments

Comments
 (0)