@@ -44,7 +44,7 @@ import scala.language.implicitConversions
4444import scala .util .control .NonFatal
4545import scala .util .Using
4646
47- /** Based on https://github.com/lampepfl/dotty/blob/3.4.2 /compiler/src/dotty/tools/repl/ReplDriver.scala
47+ /** Based on https://github.com/lampepfl/dotty/blob/3.6.4 /compiler/src/dotty/tools/repl/ReplDriver.scala
4848 * Main REPL instance, orchestrating input, compilation and presentation
4949 * */
5050class DottyReplDriver (settings : Array [String ],
@@ -66,8 +66,21 @@ class DottyReplDriver(settings: Array[String],
6666 setupRootCtx(this .settings ++ settings, rootCtx)
6767 }
6868
69+ private val incompatibleOptions : Seq [String ] = Seq (
70+ initCtx.settings.YbestEffort .name,
71+ initCtx.settings.YwithBestEffortTasty .name
72+ )
73+
6974 private def setupRootCtx (settings : Array [String ], rootCtx : Context ): Context = {
70- setup(settings, rootCtx) match
75+ val incompatible = settings.intersect(incompatibleOptions)
76+ val filteredSettings =
77+ if ! incompatible.isEmpty then
78+ inContext(rootCtx) {
79+ out.println(i " Options incompatible with repl will be ignored: ${incompatible.mkString(" , " )}" )
80+ }
81+ settings.filter(! incompatible.contains(_))
82+ else settings
83+ setup(filteredSettings, rootCtx) match
7184 case Some ((files, ictx)) => inContext(ictx) {
7285 shouldStart = true
7386 if files.nonEmpty then out.println(i " Ignoring spurious arguments: $files%, % " )
@@ -81,7 +94,11 @@ class DottyReplDriver(settings: Array[String],
8194
8295 /** the initial, empty state of the REPL session */
8396 final def initialState : State =
84- State (0 , 0 , Map .empty, Set .empty, rootCtx)
97+ val emptyState = State (0 , 0 , Map .empty, Set .empty, false , rootCtx)
98+ val initScript = rootCtx.settings.replInitScript.value(using rootCtx)
99+ initScript.trim() match
100+ case " " => emptyState
101+ case script => run(script)(using emptyState)
85102
86103 /** Reset state of repl to the initial state
87104 *
@@ -184,11 +201,6 @@ class DottyReplDriver(settings: Array[String],
184201 interpret(ParseResult .complete(input))
185202 }
186203
187- final def runQuietly (input : String )(using State ): State = runBody {
188- val parsed = ParseResult (input)
189- interpret(parsed, quiet = true )
190- }
191-
192204 protected def runBody (body : => State ): State = rendering.classLoader()(using rootCtx).asContext(withRedirectedOutput(body))
193205
194206 // TODO: i5069
@@ -256,10 +268,10 @@ class DottyReplDriver(settings: Array[String],
256268 .getOrElse(Nil )
257269 end completions
258270
259- protected def interpret (res : ParseResult , quiet : Boolean = false )(using state : State ): State = {
271+ protected def interpret (res : ParseResult )(using state : State ): State = {
260272 res match {
261273 case parsed : Parsed if parsed.trees.nonEmpty =>
262- compile(parsed, state, quiet )
274+ compile(parsed, state)
263275
264276 case SyntaxErrors (_, errs, _) =>
265277 displayErrors(errs)
@@ -277,7 +289,7 @@ class DottyReplDriver(settings: Array[String],
277289 }
278290
279291 /** Compile `parsed` trees and evolve `state` in accordance */
280- private def compile (parsed : Parsed , istate : State , quiet : Boolean = false ): State = {
292+ private def compile (parsed : Parsed , istate : State ): State = {
281293 def extractNewestWrapper (tree : untpd.Tree ): Name = tree match {
282294 case PackageDef (_, (obj : untpd.ModuleDef ) :: Nil ) => obj.name.moduleClassName
283295 case _ => nme.NO_NAME
@@ -328,11 +340,9 @@ class DottyReplDriver(settings: Array[String],
328340 given Ordering [Diagnostic ] =
329341 Ordering [(Int , Int , Int )].on(d => (d.pos.line, - d.level, d.pos.column))
330342
331- if (! quiet) {
332- (definitions ++ warnings)
333- .sorted
334- .foreach(printDiagnostic)
335- }
343+ (if istate.quiet then warnings else definitions ++ warnings)
344+ .sorted
345+ .foreach(printDiagnostic)
336346
337347 updatedState
338348 }
@@ -507,6 +517,8 @@ class DottyReplDriver(settings: Array[String],
507517 rootCtx = setupRootCtx(tokenize(arg).toArray, rootCtx)
508518 state.copy(context = rootCtx)
509519
520+ case Silent => state.copy(quiet = ! state.quiet)
521+
510522 case Quit =>
511523 // end of the world!
512524 // MP: slight variation from original DottyReplDriver to support exiting via the Quit command
0 commit comments