diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 13 | ||||
-rw-r--r-- | test/files/neg/t5357.check | 4 | ||||
-rw-r--r-- | test/files/neg/t5357.scala | 9 |
3 files changed, 22 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 5881821ab3..d7bfcfc314 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1745,11 +1745,16 @@ self => * }}} */ def pattern1(): Tree = pattern2() match { - case p @ Ident(name) if treeInfo.isVarPattern(p) && in.token == COLON => - atPos(p.pos.startOrPoint, in.skipToken()) { Typed(p, compoundType()) } - case p => - p + case p @ Ident(name) if in.token == COLON => + if (treeInfo.isVarPattern(p)) + atPos(p.pos.startOrPoint, in.skipToken())(Typed(p, compoundType())) + else { + syntaxError(in.offset, "Pattern variables must start with a lower-case letter. (SLS 8.1.1.)") + p + } + case p => p } + /** {{{ * Pattern2 ::= varid [ @ Pattern3 ] * | Pattern3 diff --git a/test/files/neg/t5357.check b/test/files/neg/t5357.check new file mode 100644 index 0000000000..3385559071 --- /dev/null +++ b/test/files/neg/t5357.check @@ -0,0 +1,4 @@ +t5357.scala:5: error: Pattern variables must start with a lower-case letter. (SLS 8.1.1.) + case A: N => 1 + ^ +one error found diff --git a/test/files/neg/t5357.scala b/test/files/neg/t5357.scala new file mode 100644 index 0000000000..369a5568a4 --- /dev/null +++ b/test/files/neg/t5357.scala @@ -0,0 +1,9 @@ +trait M + +case class N() extends M { + def mytest(x: M) = x match { + case A: N => 1 + case _ => 0 + } +} + |