diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 96b82d2336b9..d5dce6dc5212 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2908,14 +2908,18 @@ object Parsers { */ def pattern3(location: Location): Tree = val p = infixPattern() - if location.inArgs && followingIsVararg() then + if followingIsVararg() then val start = in.skipToken() - p match - case p @ Ident(name) if name.isVarPattern => - Typed(p, atSpan(start) { Ident(tpnme.WILDCARD_STAR) }) - case _ => - syntaxError(em"`*` must follow pattern variable", start) - p + if location.inArgs then + p match + case p @ Ident(name) if name.isVarPattern => + Typed(p, atSpan(start) { Ident(tpnme.WILDCARD_STAR) }) + case _ => + syntaxError(em"`*` must follow pattern variable", start) + p + else + syntaxError(em"bad use of `*` - sequence pattern not allowed here", start) + p else p /** Pattern2 ::= [id `@'] Pattern3 diff --git a/tests/neg/i8715.check b/tests/neg/i8715.check new file mode 100644 index 000000000000..c00e5e150193 --- /dev/null +++ b/tests/neg/i8715.check @@ -0,0 +1,4 @@ +-- Error: tests/neg/i8715.scala:2:46 ----------------------------------------------------------------------------------- +2 |def Test = List(42) match { case List(xs @ (ys*)) => xs } // error + | ^ + | bad use of `*` - sequence pattern not allowed here diff --git a/tests/neg/i8715.scala b/tests/neg/i8715.scala new file mode 100644 index 000000000000..90610fd788f8 --- /dev/null +++ b/tests/neg/i8715.scala @@ -0,0 +1,2 @@ +@main +def Test = List(42) match { case List(xs @ (ys*)) => xs } // error diff --git a/tests/pos/i8715.scala b/tests/pos/i8715.scala deleted file mode 100644 index 0490ce53c8cf..000000000000 --- a/tests/pos/i8715.scala +++ /dev/null @@ -1,2 +0,0 @@ -@main -def Test = List(42) match { case List(xs @ (ys*)) => xs }