@@ -29,6 +29,7 @@ import dotty.tools.dotc.util.{SourceFile, SourcePosition}
2929import dotty .tools .dotc .{CompilationUnit , Driver }
3030import dotty .tools .dotc .config .CompilerCommand
3131import dotty .tools .io ._
32+ import dotty .tools .runner .ScalaClassLoader .*
3233import org .jline .reader ._
3334
3435import scala .annotation .tailrec
@@ -62,7 +63,7 @@ case class State(objectIndex: Int,
6263/** Main REPL instance, orchestrating input, compilation and presentation */
6364class ReplDriver (settings : Array [String ],
6465 out : PrintStream = Console .out,
65- classLoader : Option [ClassLoader ] = None ) extends Driver {
66+ classLoader : Option [ClassLoader ] = None ) extends Driver :
6667
6768 /** Overridden to `false` in order to not have to give sources on the
6869 * commandline
@@ -161,15 +162,17 @@ class ReplDriver(settings: Array[String],
161162 else loop(interpret(res)(state))
162163 }
163164
164- try withRedirectedOutput { loop(initialState) }
165+ try runBody { loop(initialState) }
165166 finally terminal.close()
166167 }
167168
168- final def run (input : String )(implicit state : State ): State = withRedirectedOutput {
169+ final def run (input : String )(implicit state : State ): State = runBody {
169170 val parsed = ParseResult (input)(state)
170171 interpret(parsed)
171172 }
172173
174+ private def runBody (body : => State ): State = rendering.classLoader()(using rootCtx).asContext(withRedirectedOutput(body))
175+
173176 // TODO: i5069
174177 final def bind (name : String , value : Any )(implicit state : State ): State = state
175178
@@ -455,4 +458,5 @@ class ReplDriver(settings: Array[String],
455458 private def printDiagnostic (dia : Diagnostic )(implicit state : State ) = dia.level match
456459 case interfaces.Diagnostic .INFO => out.println(dia.msg) // print REPL's special info diagnostics directly to out
457460 case _ => ReplConsoleReporter .doReport(dia)(using state.context)
458- }
461+
462+ end ReplDriver
0 commit comments