Skip to content

REPL: display the compiler + Java version on startup #13193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/repl/JLineTerminal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class JLineTerminal extends java.io.Closeable {
private def blue(str: String)(using Context) =
if (ctx.settings.color.value != "never") Console.BLUE + str + Console.RESET
else str
private def prompt(using Context) = blue("scala> ")
private def prompt(using Context) = blue("\nscala> ")
private def newLinePrompt(using Context) = blue(" | ")

/** Blockingly read line from `System.in`
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets

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

out.println(
s"""Welcome to Scala $simpleVersionString ($javaVersion, Java $javaVmName).
|Type in expressions for evaluation. Or try :help.""".stripMargin)

/** Blockingly read a line, getting back a parse result */
def readLine(state: State): ParseResult = {
val completer: Completer = { (_, line, candidates) =>
Expand Down Expand Up @@ -208,7 +213,7 @@ class ReplDriver(settings: Array[String],
}

private def interpret(res: ParseResult)(implicit state: State): State = {
val newState = res match {
res match {
case parsed: Parsed if parsed.trees.nonEmpty =>
compile(parsed, state)

Expand All @@ -225,11 +230,6 @@ class ReplDriver(settings: Array[String],
case _ => // new line, empty tree
state
}
inContext(newState.context) {
if (!ctx.settings.XreplDisableDisplay.value)
out.println()
newState
}
}

/** Compile `parsed` trees and evolve `state` in accordance */
Expand Down
9 changes: 0 additions & 9 deletions compiler/test/dotty/tools/repl/LoadTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,19 @@ class LoadTests extends ReplTest {
|""".stripMargin,
defs = """|Hello, World!
|def helloWorld: String
|
|
|""".stripMargin,
runCode = "helloWorld",
output = """|val res0: String = Hello, World!
|
|""".stripMargin
)

@Test def maindef = loadTest(
file = """|@main def helloWorld = println("Hello, World!")
|""".stripMargin,
defs = """|def helloWorld: Unit
|
|
|""".stripMargin,
runCode = "helloWorld",
output = """|Hello, World!
|
|""".stripMargin
)

Expand All @@ -44,13 +38,10 @@ class LoadTests extends ReplTest {
|""".stripMargin,
defs = """|def helloWorld: Unit
|def helloTo(name: String): Unit
|
|
|""".stripMargin,
runCode = """helloWorld; helloTo("Scala")""",
output = """|Hello, World!
|Hello, Scala!
|
|""".stripMargin
)

Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class ReplCompilerTests extends ReplTest {
run("""val r = raw"\d+".r""")
} andThen { implicit state =>
run("""val r() = "abc"""")
assertEquals("scala.MatchError: abc (of class java.lang.String)", storedOutput().linesIterator.drop(2).next())
assertEquals("scala.MatchError: abc (of class java.lang.String)", storedOutput().linesIterator.drop(1).next())
}
@Test def `i10214 must show MatchError on literal type` = fromInitialState { implicit state =>
run("val (x: 1) = 2")
Expand Down
4 changes: 0 additions & 4 deletions compiler/test/dotty/tools/repl/ReplTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
inputRes.foldLeft(initialState) { (state, input) =>
val (out, nstate) = evaluate(state, input)
out.linesIterator.foreach(buf.append)

assert(out.endsWith("\n"),
s"Expected output of $input to end with newline")

nstate
}
buf.toList.flatMap(filterEmpties)
Expand Down