Skip to content

Commit 23c363e

Browse files
committed
Provide script engine rendering object with parent class loader
The point of this change is to make it possible to cast script engine's output to classes from the calling context, which is currently impossible due to lack of a common parent classloader, see: https://stackoverflow.com/questions/2591779/cast-across-classloader
1 parent 59fcde7 commit 23c363e

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ScriptEngine extends AbstractScriptEngine {
2424
"-color:never",
2525
"-Xrepl-disable-display"
2626
), Console.out, None)
27-
private val rendering = new Rendering
27+
private val rendering = new Rendering(Option(getClass.getClassLoader))
2828
private var state: State = driver.initialState
2929

3030
def getFactory: ScriptEngineFactory = new ScriptEngine.Factory

tests/run-with-compiler/scripting.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ object Test {
33
val m = new javax.script.ScriptEngineManager(getClass().getClassLoader())
44
val e = m.getEngineByName("scala")
55
println(e.eval("42"))
6+
println(e.eval("Some(42)").asInstanceOf[Option[Int]].get)
67
}
78
}

0 commit comments

Comments
 (0)