From 40020f3c5f62a60a1758dd2e886ef31204a6a650 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 2 Apr 2019 13:03:16 +0200 Subject: [PATCH] Fix #4934: Issue an error in acceptStatSepUnlessAtEnd --- .../src/dotty/tools/dotc/parsing/Parsers.scala | 1 + tests/neg/i1779.scala | 2 +- tests/neg/i4934.scala | 10 ++++++++++ tests/neg/parser-stability-16.scala | 2 +- tests/neg/parser-stability-17.scala | 2 +- tests/neg/parser-stability-23.scala | 2 +- tests/neg/parser-stability-4.scala | 2 +- tests/run/weak-conformance.scala | 14 +++++++------- 8 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 tests/neg/i4934.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 93a3a1e9c9d5..1464c3983d78 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -341,6 +341,7 @@ object Parsers { case NEWLINE | NEWLINES => in.nextToken() case SEMI => in.nextToken() case _ => + syntaxError("end of statement expected") in.nextToken() // needed to ensure progress; otherwise we might cycle forever accept(SEMI) } diff --git a/tests/neg/i1779.scala b/tests/neg/i1779.scala index cce32b57c89e..6435d2bc3491 100644 --- a/tests/neg/i1779.scala +++ b/tests/neg/i1779.scala @@ -8,6 +8,6 @@ object Test { def f = { val _parent = 3 q"val hello = $_parent" - q"class $_" // error + q"class $_" // error // error } // error } diff --git a/tests/neg/i4934.scala b/tests/neg/i4934.scala new file mode 100644 index 000000000000..597f684f54d7 --- /dev/null +++ b/tests/neg/i4934.scala @@ -0,0 +1,10 @@ +object Foo { + val a = ""); // error: end of statement expected +} +// From #5824: +object Main { + def main(args: Array[String]): Unit = { + val foo = 123 ""; // error: end of statement expected + println(foo) + } +} \ No newline at end of file diff --git a/tests/neg/parser-stability-16.scala b/tests/neg/parser-stability-16.scala index 5d6fcdd98c0c..9ba58d0219f2 100644 --- a/tests/neg/parser-stability-16.scala +++ b/tests/neg/parser-stability-16.scala @@ -2,5 +2,5 @@ class x0[x0] { val x1 : x0 } trait x3 extends x0 { // error -x1 = 0 object // error +x1 = 0 object // error // error // error \ No newline at end of file diff --git a/tests/neg/parser-stability-17.scala b/tests/neg/parser-stability-17.scala index ff603a677378..db1f212fc4ab 100644 --- a/tests/neg/parser-stability-17.scala +++ b/tests/neg/parser-stability-17.scala @@ -1,2 +1,2 @@ trait x0[] { x0: x0 => } // error // error - class x0[x1] extends x0[x0 x0] x2 x0 // error // error + class x0[x1] extends x0[x0 x0] x2 x0 // error // error // error diff --git a/tests/neg/parser-stability-23.scala b/tests/neg/parser-stability-23.scala index b8db4d937f25..2b46f582e819 100644 --- a/tests/neg/parser-stability-23.scala +++ b/tests/neg/parser-stability-23.scala @@ -1,3 +1,3 @@ object i0 { - import Ordering.{ implicitly => } (true: Boolean) match { case _: i1 => true } // error // error + import Ordering.{ implicitly => } (true: Boolean) match { case _: i1 => true } // error // error // error } diff --git a/tests/neg/parser-stability-4.scala b/tests/neg/parser-stability-4.scala index cbaaa357759f..41be1b692022 100644 --- a/tests/neg/parser-stability-4.scala +++ b/tests/neg/parser-stability-4.scala @@ -1,3 +1,3 @@ class x0{ - def x0: x0 = (x0 => x0) => x0) // error + def x0: x0 = (x0 => x0) => x0) // error // error // error \ No newline at end of file diff --git a/tests/run/weak-conformance.scala b/tests/run/weak-conformance.scala index 7d411c1de198..5e7350bf3044 100644 --- a/tests/run/weak-conformance.scala +++ b/tests/run/weak-conformance.scala @@ -42,12 +42,12 @@ object Test extends App { locally { def f(): Int = b + 1 val x1 = if (true) b else if (true) 33 else 5.5 ; x1: Double // b is an inline val - val x2 = if (true) f() else if (true) 33 else 5.5) ; x2: AnyVal // f() is not a constant - val x3 = if (true) 5 else 11L) ; x3: Long - val x4 = if (true) 5 else if (true) 11L else 5.5) ; x4: AnyVal // Long and Double found - val x5 = if (true) 1.0f else 2) ; x5: Float - val x6 = if (true) 1.0f else 1234567890) ; x6: AnyVal // loss of precision - val x7 = if (true) b else if (true) 33 else 'a') ; x7: Char - val x8 = if (true) 5.toByte else 11) ; x8: Byte + val x2 = if (true) f() else if (true) 33 else 5.5 ; x2: AnyVal // f() is not a constant + val x3 = if (true) 5 else 11L ; x3: Long + val x4 = if (true) 5 else if (true) 11L else 5.5 ; x4: AnyVal // Long and Double found + val x5 = if (true) 1.0f else 2 ; x5: Float + val x6 = if (true) 1.0f else 1234567890 ; x6: AnyVal // loss of precision + val x7 = if (true) b else if (true) 33 else 'a' ; x7: Char + val x8 = if (true) 5.toByte else 11 ; x8: Byte } } \ No newline at end of file