@@ -29,6 +29,7 @@ import dotty.tools.dotc.util.{SourceFile, SourcePosition}
29
29
import dotty .tools .dotc .{CompilationUnit , Driver }
30
30
import dotty .tools .dotc .config .CompilerCommand
31
31
import dotty .tools .io ._
32
+ import dotty .tools .runner .ScalaClassLoader .*
32
33
import org .jline .reader ._
33
34
34
35
import scala .annotation .tailrec
@@ -62,7 +63,7 @@ case class State(objectIndex: Int,
62
63
/** Main REPL instance, orchestrating input, compilation and presentation */
63
64
class ReplDriver (settings : Array [String ],
64
65
out : PrintStream = Console .out,
65
- classLoader : Option [ClassLoader ] = None ) extends Driver {
66
+ classLoader : Option [ClassLoader ] = None ) extends Driver :
66
67
67
68
/** Overridden to `false` in order to not have to give sources on the
68
69
* commandline
@@ -161,15 +162,17 @@ class ReplDriver(settings: Array[String],
161
162
else loop(interpret(res)(state))
162
163
}
163
164
164
- try withRedirectedOutput { loop(initialState) }
165
+ try runBody { loop(initialState) }
165
166
finally terminal.close()
166
167
}
167
168
168
- final def run (input : String )(implicit state : State ): State = withRedirectedOutput {
169
+ final def run (input : String )(implicit state : State ): State = runBody {
169
170
val parsed = ParseResult (input)(state)
170
171
interpret(parsed)
171
172
}
172
173
174
+ private def runBody (body : => State ): State = rendering.classLoader()(using rootCtx).asContext(withRedirectedOutput(body))
175
+
173
176
// TODO: i5069
174
177
final def bind (name : String , value : Any )(implicit state : State ): State = state
175
178
@@ -455,4 +458,5 @@ class ReplDriver(settings: Array[String],
455
458
private def printDiagnostic (dia : Diagnostic )(implicit state : State ) = dia.level match
456
459
case interfaces.Diagnostic .INFO => out.println(dia.msg) // print REPL's special info diagnostics directly to out
457
460
case _ => ReplConsoleReporter .doReport(dia)(using state.context)
458
- }
461
+
462
+ end ReplDriver
0 commit comments