Skip to content

Commit fd5d1bb

Browse files
committed
further cleanup, reuse dir (bug w double import)
1 parent aef5851 commit fd5d1bb

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Diff for: compiler/src/dotty/tools/repl/ReplDriver.scala

+11-9
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,8 @@ class ReplDriver(settings: Array[String],
511511
}
512512

513513
case Require(path) =>
514-
val f = new JFile(path)
515514
val jarFile = AbstractFile.getDirectory(path)
516-
if (!f.exists || jarFile == null)
515+
if (jarFile == null)
517516
out.println(s"""Cannot add "$path" to classpath.""")
518517
state
519518
else
@@ -539,15 +538,17 @@ class ReplDriver(settings: Array[String],
539538

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

548547
// add to compiler class path
549548
val prevOutputDir = rootCtx.settings.outputDir.valueIn(rootCtx.settingsState)
550-
val ctxToUse = initCtx.fresh.setSetting(rootCtx.settings.classpath, newCP)
549+
val ctxToUse = initCtx.fresh
550+
.setSetting(rootCtx.settings.classpath, newClassPath)
551+
.setSetting(rootCtx.settings.outputDir, prevOutputDir) // reuse virtual output directory
551552
rootCtx = setupRootCtx(
552553
Array(),
553554
ctxToUse,
@@ -559,10 +560,11 @@ class ReplDriver(settings: Array[String],
559560
val prevClassLoader = rendering.classLoader()(using state.context)
560561
val jarClassLoader = fromURLsParallelCapable(
561562
ClassPathFactory.newClassPath(jarFile)(using rootCtx).asURLs, prevClassLoader)
562-
val replOutputClassLoader = new AbstractFileClassLoader(
563-
prevOutputDir, jarClassLoader)
563+
// val replOutputClassLoader = new AbstractFileClassLoader(
564+
// prevOutputDir, jarClassLoader)
564565
rendering.myClassLoader = new AbstractFileClassLoader(
565-
rootCtx.settings.outputDir.valueIn(rootCtx.settingsState), replOutputClassLoader)
566+
rootCtx.settings.outputDir.valueIn(rootCtx.settingsState), jarClassLoader) //replOutputClassLoader)
567+
println(s"new classpath: ${s.context.platform.classPath(using s.context)}")
566568
out.println(s"Added '$path' to classpath.")
567569
s
568570

0 commit comments

Comments
 (0)