Skip to content

Commit b3d4fd9

Browse files
committed
Fix readLine in TestREPL to align with Ammonite reader
Needs to read several input lines at once. Enables repl test of new error messages.
1 parent 8d4d9a3 commit b3d4fd9

File tree

3 files changed

+86
-4
lines changed

3 files changed

+86
-4
lines changed

src/dotty/tools/dotc/repl/REPL.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class REPL extends Driver {
5050
object REPL {
5151
class Config {
5252
val prompt = "scala> "
53-
val continuationPrompt = " | "
53+
val continuationPrompt = " "
5454
val version = ".next (pre-alpha)"
5555

5656
def context(ctx: Context): Context = ctx

test/test/TestREPL.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@ class TestREPL(script: String) extends REPL {
2424
ctx.fresh.setSetting(ctx.settings.color, "never")
2525

2626
override def input(in: Interpreter)(implicit ctx: Context) = new InteractiveReader {
27-
val lines = script.lines
27+
val lines = script.lines.buffered
2828
def readLine(prompt: String): String = {
2929
val line = lines.next
30-
if (line.startsWith(prompt) || line.startsWith(continuationPrompt)) {
30+
val buf = new StringBuilder
31+
if (line.startsWith(prompt)) {
3132
output.println(line)
32-
line.drop(prompt.length)
33+
buf append line.drop(prompt.length)
34+
while (lines.hasNext && lines.head.startsWith(continuationPrompt)) {
35+
val continued = lines.next
36+
output.println(continued)
37+
buf append "\n"
38+
buf append continued.drop(continuationPrompt.length)
39+
}
40+
buf.toString
3341
}
3442
else readLine(prompt)
3543
}

tests/repl/errmsgs.check

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
scala> class Inv[T](x: T)
2+
defined class Inv
3+
scala> val x: List[String] = List(1)
4+
<console>:4: error: type mismatch:
5+
found : Int(1)
6+
required: String
7+
val x: List[String] = List(1)
8+
^
9+
scala> val y: List[List[String]] = List(List(1))
10+
<console>:4: error: type mismatch:
11+
found : Int(1)
12+
required: String
13+
val y: List[List[String]] = List(List(1))
14+
^
15+
scala> val z: (List[String], List[Int]) = (List(1), List("a"))
16+
<console>:4: error: type mismatch:
17+
found : Int(1)
18+
required: String
19+
val z: (List[String], List[Int]) = (List(1), List("a"))
20+
^
21+
<console>:4: error: type mismatch:
22+
found : String("a")
23+
required: Int
24+
val z: (List[String], List[Int]) = (List(1), List("a"))
25+
^
26+
scala> val a: Inv[String] = new Inv(new Inv(1))
27+
<console>:5: error: type mismatch:
28+
found : Inv[T]
29+
required: String
30+
31+
where T is a type variable with constraint >: Int(1)
32+
33+
val a: Inv[String] = new Inv(new Inv(1))
34+
^
35+
scala> val b: Inv[String] = new Inv(1)
36+
<console>:5: error: type mismatch:
37+
found : Int(1)
38+
required: String
39+
val b: Inv[String] = new Inv(1)
40+
^
41+
scala> abstract class C {
42+
type T
43+
val x: T
44+
val s: Unit = {
45+
type T = String
46+
var y: T = x
47+
locally {
48+
def f() = {
49+
type T = Int
50+
val z: T = y
51+
}
52+
f()
53+
}
54+
}
55+
}
56+
<console>:9: error: type mismatch:
57+
found : C.this.T(C.this.x)
58+
required: T'
59+
60+
where T is a type in class C
61+
T' is a type in the initalizer of value s which is an alias of String
62+
63+
var y: T = x
64+
^
65+
<console>:13: error: type mismatch:
66+
found : T(y)
67+
required: T'
68+
69+
where T is a type in the initalizer of value s which is an alias of String
70+
T' is a type in method f which is an alias of Int
71+
72+
val z: T = y
73+
^
74+
scala> :quit

0 commit comments

Comments
 (0)