summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-02-07 04:45:22 +0000
committerPaul Phillips <paulp@improving.org>2011-02-07 04:45:22 +0000
commitfcc962b1973aedf1c892aac0d1fce7e5fa32fbc0 (patch)
tree8a8fb1e4366083b7c490b4b1f43a9bd3858d6191
parent7b19ec8b1b296913adb5c226decd16f1e091c76b (diff)
downloadscala-fcc962b1973aedf1c892aac0d1fce7e5fa32fbc0.tar.gz
scala-fcc962b1973aedf1c892aac0d1fce7e5fa32fbc0.tar.bz2
scala-fcc962b1973aedf1c892aac0d1fce7e5fa32fbc0.zip
Fix for parser regression allowing 0-case match...
Fix for parser regression allowing 0-case match blocks. Closes #4217, no review.
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala8
-rw-r--r--test/files/neg/bug4217.check4
-rw-r--r--test/files/neg/bug4217.scala3
3 files changed, 13 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 21628f9864..d75d28c45f 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -1542,8 +1542,12 @@ self =>
/** CaseClauses ::= CaseClause {CaseClause}
* CaseClause ::= case Pattern [Guard] `=>' Block
*/
- def caseClauses(): List[CaseDef] = caseSeparated {
- atPos(in.offset)(makeCaseDef(pattern(), guard(), caseBlock()))
+ def caseClauses(): List[CaseDef] = {
+ val cases = caseSeparated { atPos(in.offset)(makeCaseDef(pattern(), guard(), caseBlock())) }
+ if (cases.isEmpty) // trigger error if there are no cases
+ accept(CASE)
+
+ cases
}
// IDE HOOK (so we can memoize case blocks) // needed?
diff --git a/test/files/neg/bug4217.check b/test/files/neg/bug4217.check
new file mode 100644
index 0000000000..4de9201da8
--- /dev/null
+++ b/test/files/neg/bug4217.check
@@ -0,0 +1,4 @@
+bug4217.scala:2: error: 'case' expected but '}' found.
+ 42 match { }
+ ^
+one error found
diff --git a/test/files/neg/bug4217.scala b/test/files/neg/bug4217.scala
new file mode 100644
index 0000000000..8b5c4a6e05
--- /dev/null
+++ b/test/files/neg/bug4217.scala
@@ -0,0 +1,3 @@
+object A extends Application {
+ 42 match { }
+}