diff --git a/compiler/src/dotty/tools/repl/JLineTerminal.scala b/compiler/src/dotty/tools/repl/JLineTerminal.scala index 5f43a7483841..807ae2bf5eec 100644 --- a/compiler/src/dotty/tools/repl/JLineTerminal.scala +++ b/compiler/src/dotty/tools/repl/JLineTerminal.scala @@ -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` diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index 49201b6b142f..81033f2dcc4b 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -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 @@ -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) => @@ -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) @@ -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 */ diff --git a/compiler/test/dotty/tools/repl/LoadTests.scala b/compiler/test/dotty/tools/repl/LoadTests.scala index 276a684b20e8..8dc077c05552 100644 --- a/compiler/test/dotty/tools/repl/LoadTests.scala +++ b/compiler/test/dotty/tools/repl/LoadTests.scala @@ -16,12 +16,9 @@ class LoadTests extends ReplTest { |""".stripMargin, defs = """|Hello, World! |def helloWorld: String - | - | |""".stripMargin, runCode = "helloWorld", output = """|val res0: String = Hello, World! - | |""".stripMargin ) @@ -29,12 +26,9 @@ class LoadTests extends ReplTest { file = """|@main def helloWorld = println("Hello, World!") |""".stripMargin, defs = """|def helloWorld: Unit - | - | |""".stripMargin, runCode = "helloWorld", output = """|Hello, World! - | |""".stripMargin ) @@ -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 ) diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 5da4f26c38e1..012da2b33eea 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -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") diff --git a/compiler/test/dotty/tools/repl/ReplTest.scala b/compiler/test/dotty/tools/repl/ReplTest.scala index f338c7991e6b..f39c1642a6b6 100644 --- a/compiler/test/dotty/tools/repl/ReplTest.scala +++ b/compiler/test/dotty/tools/repl/ReplTest.scala @@ -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)