Skip to content

Commit b084a23

Browse files
committed
Put quiet into State of REPL
... so that we can toggle it
1 parent 83fe5a7 commit b084a23

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ import scala.util.Using
6060
* @param valIndex the index of next value binding for free expressions
6161
* @param imports a map from object index to the list of user defined imports
6262
* @param invalidObjectIndexes the set of object indexes that failed to initialize
63+
* @param quiet whether we print evaluation results
6364
* @param context the latest compiler context
6465
*/
6566
case class State(objectIndex: Int,
6667
valIndex: Int,
6768
imports: Map[Int, List[tpd.Import]],
6869
invalidObjectIndexes: Set[Int],
70+
quiet: Boolean,
6971
context: Context):
7072
def validObjectIndexes = (1 to objectIndex).filterNot(invalidObjectIndexes.contains(_))
7173

@@ -114,7 +116,7 @@ class ReplDriver(settings: Array[String],
114116
}
115117

116118
/** the initial, empty state of the REPL session */
117-
final def initialState: State = State(0, 0, Map.empty, Set.empty, rootCtx)
119+
final def initialState: State = State(0, 0, Map.empty, Set.empty, false, rootCtx)
118120

119121
/** Reset state of repl to the initial state
120122
*
@@ -217,11 +219,6 @@ class ReplDriver(settings: Array[String],
217219
interpret(ParseResult.complete(input))
218220
}
219221

220-
final def runQuietly(input: String)(using State): State = runBody {
221-
val parsed = ParseResult(input)
222-
interpret(parsed, quiet = true)
223-
}
224-
225222
protected def runBody(body: => State): State = rendering.classLoader()(using rootCtx).asContext(withRedirectedOutput(body))
226223

227224
// TODO: i5069
@@ -290,10 +287,10 @@ class ReplDriver(settings: Array[String],
290287
.getOrElse(Nil)
291288
end completions
292289

293-
protected def interpret(res: ParseResult, quiet: Boolean = false)(using state: State): State = {
290+
protected def interpret(res: ParseResult)(using state: State): State = {
294291
res match {
295292
case parsed: Parsed if parsed.trees.nonEmpty =>
296-
compile(parsed, state, quiet)
293+
compile(parsed, state)
297294

298295
case SyntaxErrors(_, errs, _) =>
299296
displayErrors(errs)
@@ -311,7 +308,7 @@ class ReplDriver(settings: Array[String],
311308
}
312309

313310
/** Compile `parsed` trees and evolve `state` in accordance */
314-
private def compile(parsed: Parsed, istate: State, quiet: Boolean = false): State = {
311+
private def compile(parsed: Parsed, istate: State): State = {
315312
def extractNewestWrapper(tree: untpd.Tree): Name = tree match {
316313
case PackageDef(_, (obj: untpd.ModuleDef) :: Nil) => obj.name.moduleClassName
317314
case _ => nme.NO_NAME
@@ -362,7 +359,7 @@ class ReplDriver(settings: Array[String],
362359
given Ordering[Diagnostic] =
363360
Ordering[(Int, Int, Int)].on(d => (d.pos.line, -d.level, d.pos.column))
364361

365-
(if quiet then warnings else definitions ++ warnings)
362+
(if istate.quiet then warnings else definitions ++ warnings)
366363
.sorted
367364
.foreach(printDiagnostic)
368365

0 commit comments

Comments
 (0)