Skip to content

Commit

Permalink
Fix check.
Browse files Browse the repository at this point in the history
  • Loading branch information
adampauls committed Feb 13, 2022
1 parent ddac928 commit 2e004b8
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 9 deletions.
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,8 @@ object Parsers {
val next = in.lookahead.token
next == LBRACKET || next == LPAREN

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

Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,6 @@ object Scanners {
&& (token == RPAREN || token == RBRACKET || token == RBRACE || token == OUTDENT)
then
() /* skip the trailing comma */
else if token == EOF then // e.g. when the REPL is parsing "val List(x, y, _*,"
() /* skip the trailing comma */
else
reset()
case END =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Tokens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ object Tokens extends TokensCommon {

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

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

final val softModifierNames = Set(nme.inline, nme.opaque, nme.open, nme.transparent, nme.infix)
}
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/repl/Main.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dotty.tools.repl

/** Main entry point to the REPL */
// To test, run bin/scala
object Main {
def main(args: Array[String]): Unit =
new ReplDriver(args).tryRunning
Expand Down
6 changes: 5 additions & 1 deletion compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
def sawDiagnostic(d: Diagnostic): Unit =
d.pos.nonInlined match
case srcpos if srcpos.exists =>
val key = s"${relativize(srcpos.source.file.toString)}:${srcpos.line + 1}"
// If an annotated // error is placed on the last line of the file, EOF errors can show up past the last.
// Without this adjustment, it's not possible to annotate // error on errors whose position is EOF
// in some cases.
val adjustedLine = if srcpos.point == srcpos.source.length && srcpos.point > 0 then srcpos.source.offsetToLine(srcpos.point - 1) else srcpos.line
val key = s"${relativize(srcpos.source.file.toString)}:${adjustedLine + 1}"
if !seenAt(key) then unexpected += key
case srcpos =>
if !seenAt("nopos") then unpositioned += relativize(srcpos.source.file.toString)
Expand Down
3 changes: 3 additions & 0 deletions tests/neg/arg-eof.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test:
case class Widget(name: String, other: Int = 5)
Widget(name = "foo", // error // error
2 changes: 1 addition & 1 deletion tests/neg/i1679.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class A[T]
object o {
// Testing compiler crash, this test should be modified when named type argument are completely implemented
val x: A[T=Int, T=Int] = ??? // error: ']' expected, but '=' found
val x: A[T=Int, T=Int] = ??? // error: ']' expected, but '=' found // error
}
4 changes: 2 additions & 2 deletions tests/neg/t1625.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
trait T3 {
def foo(x: String*, y: String*, c: String*): Int // error: an identifier expected, but ',' found
}
def foo(x: String*, y: String*, c: String*): Int // error: an identifier expected, but ',' found // error: an identifier expected, but ',' found
}
6 changes: 6 additions & 0 deletions tests/neg/trailing-comma-pattern.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- [E032] Syntax Error: tests/neg/trailing-comma-pattern.scala:4:0 -----------------------------------------------------
4 |
|^
|pattern expected
|
| longer explanation available when compiling with `-explain`
3 changes: 3 additions & 0 deletions tests/neg/trailing-comma-pattern.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test:
val List(x, y, _*,
// error
10 changes: 10 additions & 0 deletions tests/neg/trailing-comma-pattern2.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- [E032] Syntax Error: tests/neg/trailing-comma-pattern2.scala:2:21 ---------------------------------------------------
2 | val List(x, y, _*, ) // error
| ^
| pattern expected
|
| longer explanation available when compiling with `-explain`
-- [E040] Syntax Error: tests/neg/trailing-comma-pattern2.scala:4:0 ----------------------------------------------------
4 |
|^
|'=' expected, but unindent found
3 changes: 3 additions & 0 deletions tests/neg/trailing-comma-pattern2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test:
val List(x, y, _*, ) // error
// error
3 changes: 3 additions & 0 deletions tests/pos/trailing-comma-pattern.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test:
val List(x, y, _*,
) = List(1, 2, 3)

0 comments on commit 2e004b8

Please sign in to comment.