Skip to content

Commit a03f795

Browse files
committed
Fix #3279
When using the repl through "sbt console", we used to use the class loader sbt give us. But we need a class loader that has the output directory of the compiler on the classpath
1 parent 953a385 commit a03f795

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ import dotc.core.StdNames.str
2121
* `Rendering` is no longer valid.
2222
*/
2323
private[repl] class Rendering(compiler: ReplCompiler,
24-
private var currentClassLoader: Option[ClassLoader] = None) {
24+
parentClassLoader: Option[ClassLoader] = None) {
2525

26-
private def classLoader()(implicit ctx: Context) =
27-
currentClassLoader.getOrElse {
28-
import java.net.{URL, URLClassLoader}
26+
private[this] var myClassLoader: ClassLoader = _
2927

30-
/** the compiler's classpath, as URL's */
31-
val compilerClasspath: Seq[URL] = ctx.platform.classPath(ctx).asURLs
28+
/** Class loader used to load compiled code */
29+
private[this] def classLoader()(implicit ctx: Context) =
30+
if (myClassLoader != null) myClassLoader
31+
else {
32+
val parent = parentClassLoader.getOrElse {
33+
// the compiler's classpath, as URL's
34+
val compilerClasspath = ctx.platform.classPath(ctx).asURLs
35+
new java.net.URLClassLoader(compilerClasspath.toArray, classOf[ReplDriver].getClassLoader)
36+
}
3237

33-
def parent = new URLClassLoader(compilerClasspath.toArray,
34-
classOf[ReplDriver].getClassLoader)
35-
36-
val newClsLoader = new AbstractFileClassLoader(compiler.directory,
37-
currentClassLoader.getOrElse(parent))
38-
39-
Thread.currentThread.setContextClassLoader(newClsLoader)
40-
currentClassLoader = Some(newClsLoader)
41-
newClsLoader
38+
myClassLoader = new AbstractFileClassLoader(compiler.directory, parent)
39+
// Set the current Java "context" class loader to this rendering class loader
40+
Thread.currentThread.setContextClassLoader(myClassLoader)
41+
myClassLoader
4242
}
4343

4444
/** Load the value of the symbol using reflection

0 commit comments

Comments
 (0)