Skip to content

Commit 1faade5

Browse files
committed
Reclassify test and improve error message
1 parent bf6974e commit 1faade5

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
@@ -2908,14 +2908,18 @@ object Parsers {
29082908
*/
29092909
def pattern3(location: Location): Tree =
29102910
val p = infixPattern()
2911-
if location.inArgs && followingIsVararg() then
2911+
if followingIsVararg() then
29122912
val start = in.skipToken()
2913-
p match
2914-
case p @ Ident(name) if name.isVarPattern =>
2915-
Typed(p, atSpan(start) { Ident(tpnme.WILDCARD_STAR) })
2916-
case _ =>
2917-
syntaxError(em"`*` must follow pattern variable", start)
2918-
p
2913+
if location.inArgs then
2914+
p match
2915+
case p @ Ident(name) if name.isVarPattern =>
2916+
Typed(p, atSpan(start) { Ident(tpnme.WILDCARD_STAR) })
2917+
case _ =>
2918+
syntaxError(em"`*` must follow pattern variable", start)
2919+
p
2920+
else
2921+
syntaxError(em"bad use of `*` - sequence pattern not allowed here", start)
2922+
p
29192923
else p
29202924

29212925
/** 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)