File tree 4 files changed +17
-5
lines changed
compiler/src/dotty/tools/dotc/parsing 4 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -2628,13 +2628,19 @@ object Parsers {
2628
2628
ascription(p, location)
2629
2629
else p
2630
2630
2631
- /** Pattern3 ::= InfixPattern [‘*’]
2631
+ /** Pattern3 ::= InfixPattern
2632
+ * | PatVar ‘*’
2632
2633
*/
2633
2634
def pattern3 (): Tree =
2634
2635
val p = infixPattern()
2635
2636
if followingIsVararg() then
2636
2637
atSpan(in.skipToken()) {
2637
- Typed (p, Ident (tpnme.WILDCARD_STAR ))
2638
+ p match
2639
+ case p @ Ident (name) if name.isVarPattern =>
2640
+ Typed (p, Ident (tpnme.WILDCARD_STAR ))
2641
+ case _ =>
2642
+ syntaxError(em " `*` must follow pattern variable " )
2643
+ p
2638
2644
}
2639
2645
else p
2640
2646
@@ -2726,7 +2732,7 @@ object Parsers {
2726
2732
if (in.token == RPAREN ) Nil else patterns(location)
2727
2733
2728
2734
/** ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
2729
- * | ‘(’ [Patterns ‘,’] Pattern2 ‘*’ ‘)’
2735
+ * | ‘(’ [Patterns ‘,’] PatVar ‘*’ ‘)’
2730
2736
*/
2731
2737
def argumentPatterns (): List [Tree ] =
2732
2738
inParens(patternsOpt(Location .InPatternArgs ))
Original file line number Diff line number Diff line change @@ -296,7 +296,7 @@ PatVar ::= varid
296
296
| ‘_’
297
297
Patterns ::= Pattern {‘,’ Pattern}
298
298
ArgumentPatterns ::= ‘(’ [Patterns] ‘)’ Apply(fn, pats)
299
- | ‘(’ [Patterns ‘,’] Pattern2 ‘*’ ‘)’
299
+ | ‘(’ [Patterns ‘,’] PatVar ‘*’ ‘)’
300
300
```
301
301
302
302
### Type and Value Parameters
Original file line number Diff line number Diff line change @@ -290,7 +290,7 @@ PatVar ::= varid
290
290
| ‘_’
291
291
Patterns ::= Pattern {‘,’ Pattern}
292
292
ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
293
- | ‘(’ [Patterns ‘,’] Pattern2 ‘*’ ‘)’
293
+ | ‘(’ [Patterns ‘,’] PatVar ‘*’ ‘)’
294
294
```
295
295
296
296
### Type and Value Parameters
Original file line number Diff line number Diff line change
1
+
2
+ val x = Seq (1 , 2 ) match
3
+ case Seq (x, y* ) => println(y) // prints List(2) which looks correct
4
+
5
+ val y = Seq (1 , 2 ) match
6
+ case Seq (x, (y)* ) => println(y) // error
You can’t perform that action at this time.
0 commit comments