Skip to content

Commit 9f1c3dd

Browse files
committed
Took into account code review comments
1 parent 5027832 commit 9f1c3dd

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ReplDriver(settings: Array[String],
7272
}
7373

7474
/** the initial, empty state of the REPL session */
75-
protected[this] def initState = State(0, 0, Nil, rootCtx)
75+
final def initialState = State(0, 0, Nil, rootCtx)
7676

7777
/** Reset state of repl to the initial state
7878
*
@@ -97,15 +97,15 @@ class ReplDriver(settings: Array[String],
9797
// is called, we're in business
9898
resetToInitial()
9999

100-
final def runUntilQuit(): State = runUntilQuit(initState)
100+
final def runUntilQuit(): State = runUntilQuit(initialState)
101101

102102
/** Run REPL with `state` until `:quit` command found
103103
*
104104
* This method is the main entry point into the REPL. Its effects are not
105105
* observable outside of the CLI, for this reason, most helper methods are
106106
* `protected final` to facilitate testing.
107107
*/
108-
final def runUntilQuit(initialState: State): State = {
108+
final def runUntilQuit(initialState: State = initialState): State = {
109109
val terminal = new JLineTerminal()
110110

111111
/** Blockingly read a line, getting back a parse result */
@@ -139,15 +139,9 @@ class ReplDriver(settings: Array[String],
139139
val parsed = ParseResult(input)(state.context)
140140
interpret(parsed)
141141
}
142-
143-
final def bindValues(bindPairs: ZippedTraversable2[String, Any]): State = {
144-
bindPairs.foldLeft(initState) {
145-
case (state, (name, value)) => bind(name, value)(state)
146-
}
147-
}
148142

149143
// TODO: i3007
150-
private def bind(name:String, value:Any)(implicit state: State): State = state
144+
final def bind(name:String, value:Any)(implicit state: State): State = state
151145

152146
private def withRedirectedOutput(op: => State): State =
153147
Console.withOut(out) { Console.withErr(out) { op } }
@@ -321,7 +315,7 @@ class ReplDriver(settings: Array[String],
321315

322316
case Reset =>
323317
resetToInitial()
324-
initState
318+
initialState
325319

326320
case Imports =>
327321
state.imports.foreach(i => out.println(SyntaxHighlighting(i.show(state.context))))

compiler/test/dotty/tools/repl/ReplTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ReplTest private (out: ByteArrayOutputStream) extends ReplDriver(
3232
storedOutput()
3333

3434
def fromInitialState[A](op: State => A): A =
35-
op(initState)
35+
op(initialState)
3636

3737
implicit class TestingState(state: State) {
3838
def andThen[A](op: State => A): A = op(state)

compiler/test/dotty/tools/repl/ScriptedTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ScriptedTests extends ReplTest with MessageRendering {
6565
resetToInitial()
6666
val inputRes = extractInputs(prompt)
6767
val buf = new ArrayBuffer[String]
68-
inputRes.foldLeft(initState) { (state, input) =>
68+
inputRes.foldLeft(initialState) { (state, input) =>
6969
val (out, nstate) = evaluate(state, input, prompt)
7070
buf.append(out)
7171
nstate

sbt-bridge/src/xsbt/ConsoleInterface.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ class ConsoleInterface {
3535

3636
val driver = new ReplDriver(completeArgs, classLoader = Some(loader))
3737

38-
val s0 = driver.bindValues((bindNames, bindValues).zipped)
38+
val s0 = (bindNames, bindValues).zipped.foldLeft(driver.initialState) {
39+
case (state, (name, value)) => driver.bind(name, value)(state)
40+
}
41+
3942
val s1 = driver.run(initialCommands)(s0)
4043
// TODO handle failure during initialisation
4144
val s2 = driver.runUntilQuit(s1)

0 commit comments

Comments
 (0)