Skip to content

Commit 8b2afe5

Browse files
Merge pull request #13193 from dwijnand/display-compiler-version-in-repl
REPL: display the compiler + Java version on startup
2 parents 8041a9e + 2b1b622 commit 8b2afe5

File tree

5 files changed

+8
-21
lines changed

5 files changed

+8
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class JLineTerminal extends java.io.Closeable {
2828
private def blue(str: String)(using Context) =
2929
if (ctx.settings.color.value != "never") Console.BLUE + str + Console.RESET
3030
else str
31-
private def prompt(using Context) = blue("scala> ")
31+
private def prompt(using Context) = blue("\nscala> ")
3232
private def newLinePrompt(using Context) = blue(" | ")
3333

3434
/** Blockingly read line from `System.in`

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets
55

66
import dotty.tools.dotc.ast.Trees._
77
import dotty.tools.dotc.ast.{tpd, untpd}
8+
import dotty.tools.dotc.config.Properties.{javaVersion, javaVmName, simpleVersionString}
89
import dotty.tools.dotc.core.Contexts._
910
import dotty.tools.dotc.core.Phases.{unfusedPhases, typerPhase}
1011
import dotty.tools.dotc.core.Denotations.Denotation
@@ -124,6 +125,10 @@ class ReplDriver(settings: Array[String],
124125
final def runUntilQuit(initialState: State = initialState): State = {
125126
val terminal = new JLineTerminal
126127

128+
out.println(
129+
s"""Welcome to Scala $simpleVersionString ($javaVersion, Java $javaVmName).
130+
|Type in expressions for evaluation. Or try :help.""".stripMargin)
131+
127132
/** Blockingly read a line, getting back a parse result */
128133
def readLine(state: State): ParseResult = {
129134
val completer: Completer = { (_, line, candidates) =>
@@ -208,7 +213,7 @@ class ReplDriver(settings: Array[String],
208213
}
209214

210215
private def interpret(res: ParseResult)(implicit state: State): State = {
211-
val newState = res match {
216+
res match {
212217
case parsed: Parsed if parsed.trees.nonEmpty =>
213218
compile(parsed, state)
214219

@@ -225,11 +230,6 @@ class ReplDriver(settings: Array[String],
225230
case _ => // new line, empty tree
226231
state
227232
}
228-
inContext(newState.context) {
229-
if (!ctx.settings.XreplDisableDisplay.value)
230-
out.println()
231-
newState
232-
}
233233
}
234234

235235
/** Compile `parsed` trees and evolve `state` in accordance */

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,19 @@ class LoadTests extends ReplTest {
1616
|""".stripMargin,
1717
defs = """|Hello, World!
1818
|def helloWorld: String
19-
|
20-
|
2119
|""".stripMargin,
2220
runCode = "helloWorld",
2321
output = """|val res0: String = Hello, World!
24-
|
2522
|""".stripMargin
2623
)
2724

2825
@Test def maindef = loadTest(
2926
file = """|@main def helloWorld = println("Hello, World!")
3027
|""".stripMargin,
3128
defs = """|def helloWorld: Unit
32-
|
33-
|
3429
|""".stripMargin,
3530
runCode = "helloWorld",
3631
output = """|Hello, World!
37-
|
3832
|""".stripMargin
3933
)
4034

@@ -44,13 +38,10 @@ class LoadTests extends ReplTest {
4438
|""".stripMargin,
4539
defs = """|def helloWorld: Unit
4640
|def helloTo(name: String): Unit
47-
|
48-
|
4941
|""".stripMargin,
5042
runCode = """helloWorld; helloTo("Scala")""",
5143
output = """|Hello, World!
5244
|Hello, Scala!
53-
|
5445
|""".stripMargin
5546
)
5647

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class ReplCompilerTests extends ReplTest {
218218
run("""val r = raw"\d+".r""")
219219
} andThen { implicit state =>
220220
run("""val r() = "abc"""")
221-
assertEquals("scala.MatchError: abc (of class java.lang.String)", storedOutput().linesIterator.drop(2).next())
221+
assertEquals("scala.MatchError: abc (of class java.lang.String)", storedOutput().linesIterator.drop(1).next())
222222
}
223223
@Test def `i10214 must show MatchError on literal type` = fromInitialState { implicit state =>
224224
run("val (x: 1) = 2")

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
7474
inputRes.foldLeft(initialState) { (state, input) =>
7575
val (out, nstate) = evaluate(state, input)
7676
out.linesIterator.foreach(buf.append)
77-
78-
assert(out.endsWith("\n"),
79-
s"Expected output of $input to end with newline")
80-
8177
nstate
8278
}
8379
buf.toList.flatMap(filterEmpties)

0 commit comments

Comments
 (0)