Skip to content

Commit

Permalink
Reclassify test and improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jun 26, 2023
1 parent bf6974e commit 1faade5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
18 changes: 11 additions & 7 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i8715.check
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tests/neg/i8715.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@main
def Test = List(42) match { case List(xs @ (ys*)) => xs } // error
2 changes: 0 additions & 2 deletions tests/pos/i8715.scala

This file was deleted.

0 comments on commit 1faade5

Please sign in to comment.