Skip to content

Commit 81dc79a

Browse files
committed
Reclassify test and improve error message
1 parent 7995bfd commit 81dc79a

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,14 +2882,18 @@ object Parsers {
28822882
*/
28832883
def pattern3(location: Location): Tree =
28842884
val p = infixPattern()
2885-
if location.inArgs && followingIsVararg() then
2885+
if followingIsVararg() then
28862886
val start = in.skipToken()
2887-
p match
2888-
case p @ Ident(name) if name.isVarPattern =>
2889-
Typed(p, atSpan(start) { Ident(tpnme.WILDCARD_STAR) })
2890-
case _ =>
2891-
syntaxError(em"`*` must follow pattern variable", start)
2892-
p
2887+
if location.inArgs then
2888+
p match
2889+
case p @ Ident(name) if name.isVarPattern =>
2890+
Typed(p, atSpan(start) { Ident(tpnme.WILDCARD_STAR) })
2891+
case _ =>
2892+
syntaxError(em"`*` must follow pattern variable", start)
2893+
p
2894+
else
2895+
syntaxError(em"bad use of `*` - sequence pattern not allowed here", start)
2896+
p
28932897
else p
28942898

28952899
/** Pattern2 ::= [id `@'] Pattern3

tests/neg/i8715.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg/i8715.scala:2:46 -----------------------------------------------------------------------------------
2+
2 |def Test = List(42) match { case List(xs @ (ys*)) => xs } // error
3+
| ^
4+
| bad use of `*` - sequence pattern not allowed here

tests/neg/i8715.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@main
2+
def Test = List(42) match { case List(xs @ (ys*)) => xs } // error

tests/pos/i8715.scala

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)