Skip to content

Commit 57b3864

Browse files
aherlihytgodzik
authored andcommitted
further cleanup, reuse dir (bug w double import)
[Cherry-picked 1ac09e6]
1 parent 6ed6988 commit 57b3864

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,8 @@ class ReplDriver(settings: Array[String],
514514
}
515515

516516
case Require(path) =>
517-
val f = new JFile(path)
518517
val jarFile = AbstractFile.getDirectory(path)
519-
if (!f.exists || jarFile == null)
518+
if (jarFile == null)
520519
out.println(s"""Cannot add "$path" to classpath.""")
521520
state
522521
else
@@ -542,15 +541,17 @@ class ReplDriver(settings: Array[String],
542541

543542
val existingClass = entries.filter(_.ext.isClass).find(tryClassLoad(_).isDefined)
544543
if (existingClass.nonEmpty)
545-
out.println(s"The path '$f' cannot be loaded, it contains a classfile that already exists on the classpath: ${existingClass.get}")
544+
out.println(s"The path '$path' cannot be loaded, it contains a classfile that already exists on the classpath: ${existingClass.get}")
546545
state
547546
else
548-
val cp = state.context.platform.classPath(using state.context).asClassPathString
549-
val newCP = s"$cp${JFile.pathSeparator}$path"
547+
val prevClassPath = state.context.platform.classPath(using state.context).asClassPathString
548+
val newClassPath = s"$prevClassPath${JFile.pathSeparator}$path"
550549

551550
// add to compiler class path
552551
val prevOutputDir = rootCtx.settings.outputDir.valueIn(rootCtx.settingsState)
553-
val ctxToUse = initCtx.fresh.setSetting(rootCtx.settings.classpath, newCP)
552+
val ctxToUse = initCtx.fresh
553+
.setSetting(rootCtx.settings.classpath, newClassPath)
554+
.setSetting(rootCtx.settings.outputDir, prevOutputDir) // reuse virtual output directory
554555
rootCtx = setupRootCtx(
555556
Array(),
556557
ctxToUse,
@@ -562,10 +563,11 @@ class ReplDriver(settings: Array[String],
562563
val prevClassLoader = rendering.classLoader()(using state.context)
563564
val jarClassLoader = fromURLsParallelCapable(
564565
ClassPathFactory.newClassPath(jarFile)(using rootCtx).asURLs, prevClassLoader)
565-
val replOutputClassLoader = new AbstractFileClassLoader(
566-
prevOutputDir, jarClassLoader)
566+
// val replOutputClassLoader = new AbstractFileClassLoader(
567+
// prevOutputDir, jarClassLoader)
567568
rendering.myClassLoader = new AbstractFileClassLoader(
568-
rootCtx.settings.outputDir.valueIn(rootCtx.settingsState), replOutputClassLoader)
569+
rootCtx.settings.outputDir.valueIn(rootCtx.settingsState), jarClassLoader) //replOutputClassLoader)
570+
println(s"new classpath: ${s.context.platform.classPath(using s.context)}")
569571
out.println(s"Added '$path' to classpath.")
570572
s
571573

0 commit comments

Comments
 (0)