From fcc962b1973aedf1c892aac0d1fce7e5fa32fbc0 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 7 Feb 2011 04:45:22 +0000 Subject: Fix for parser regression allowing 0-case match... Fix for parser regression allowing 0-case match blocks. Closes #4217, no review. --- src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 8 ++++++-- test/files/neg/bug4217.check | 4 ++++ test/files/neg/bug4217.scala | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/files/neg/bug4217.check create mode 100644 test/files/neg/bug4217.scala 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 { } +} -- cgit v1.2.3