Skip to content

Commit 2e004b8

Browse files
committed
Fix check.
1 parent ddac928 commit 2e004b8

13 files changed

+41
-9
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,8 @@ object Parsers {
881881
val next = in.lookahead.token
882882
next == LBRACKET || next == LPAREN
883883

884-
/** Is current ident a `*`, and is it followed by a `)` or `, )`? */
884+
/** Is current ident a `*`, and is it followed by a `)`, `, )`, `,EOF`? The latter two are not
885+
syntactically valid, but we need to include them here for error recovery. */
885886
def followingIsVararg(): Boolean =
886887
in.isIdent(nme.raw.STAR) && {
887888
val lookahead = in.LookaheadScanner()
@@ -890,7 +891,7 @@ object Parsers {
890891
|| lookahead.token == COMMA
891892
&& {
892893
lookahead.nextToken()
893-
lookahead.token == RPAREN
894+
lookahead.token == RPAREN || lookahead.token == EOF
894895
}
895896
}
896897

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,6 @@ object Scanners {
659659
&& (token == RPAREN || token == RBRACKET || token == RBRACE || token == OUTDENT)
660660
then
661661
() /* skip the trailing comma */
662-
else if token == EOF then // e.g. when the REPL is parsing "val List(x, y, _*,"
663-
() /* skip the trailing comma */
664662
else
665663
reset()
666664
case END =>

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ object Tokens extends TokensCommon {
285285

286286
final val endMarkerTokens = identifierTokens | BitSet(IF, WHILE, FOR, MATCH, TRY, NEW, THROW, GIVEN, VAL, THIS)
287287

288-
final val skipStopTokens = BitSet(SEMI, NEWLINE, NEWLINES, RBRACE, RPAREN, RBRACKET, OUTDENT)
288+
final val skipStopTokens = BitSet(SEMI, NEWLINE, NEWLINES, RBRACE, RPAREN, RBRACKET, OUTDENT, COMMA)
289289

290290
final val softModifierNames = Set(nme.inline, nme.opaque, nme.open, nme.transparent, nme.infix)
291291
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools.repl
22

33
/** Main entry point to the REPL */
4+
// To test, run bin/scala
45
object Main {
56
def main(args: Array[String]): Unit =
67
new ReplDriver(args).tryRunning

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
825825
def sawDiagnostic(d: Diagnostic): Unit =
826826
d.pos.nonInlined match
827827
case srcpos if srcpos.exists =>
828-
val key = s"${relativize(srcpos.source.file.toString)}:${srcpos.line + 1}"
828+
// If an annotated // error is placed on the last line of the file, EOF errors can show up past the last.
829+
// Without this adjustment, it's not possible to annotate // error on errors whose position is EOF
830+
// in some cases.
831+
val adjustedLine = if srcpos.point == srcpos.source.length && srcpos.point > 0 then srcpos.source.offsetToLine(srcpos.point - 1) else srcpos.line
832+
val key = s"${relativize(srcpos.source.file.toString)}:${adjustedLine + 1}"
829833
if !seenAt(key) then unexpected += key
830834
case srcpos =>
831835
if !seenAt("nopos") then unpositioned += relativize(srcpos.source.file.toString)

tests/neg/arg-eof.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test:
2+
case class Widget(name: String, other: Int = 5)
3+
Widget(name = "foo", // error // error

tests/neg/i1679.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class A[T]
22
object o {
33
// Testing compiler crash, this test should be modified when named type argument are completely implemented
4-
val x: A[T=Int, T=Int] = ??? // error: ']' expected, but '=' found
4+
val x: A[T=Int, T=Int] = ??? // error: ']' expected, but '=' found // error
55
}

tests/neg/t1625.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
trait T3 {
2-
def foo(x: String*, y: String*, c: String*): Int // error: an identifier expected, but ',' found
3-
}
2+
def foo(x: String*, y: String*, c: String*): Int // error: an identifier expected, but ',' found // error: an identifier expected, but ',' found
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- [E032] Syntax Error: tests/neg/trailing-comma-pattern.scala:4:0 -----------------------------------------------------
2+
4 |
3+
|^
4+
|pattern expected
5+
|
6+
| longer explanation available when compiling with `-explain`
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test:
2+
val List(x, y, _*,
3+
// error
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- [E032] Syntax Error: tests/neg/trailing-comma-pattern2.scala:2:21 ---------------------------------------------------
2+
2 | val List(x, y, _*, ) // error
3+
| ^
4+
| pattern expected
5+
|
6+
| longer explanation available when compiling with `-explain`
7+
-- [E040] Syntax Error: tests/neg/trailing-comma-pattern2.scala:4:0 ----------------------------------------------------
8+
4 |
9+
|^
10+
|'=' expected, but unindent found
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test:
2+
val List(x, y, _*, ) // error
3+
// error
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test:
2+
val List(x, y, _*,
3+
) = List(1, 2, 3)

0 commit comments

Comments
 (0)