File tree Expand file tree Collapse file tree 4 files changed +17
-5
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 4 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -2628,13 +2628,19 @@ object Parsers {
26282628 ascription(p, location)
26292629 else p
26302630
2631- /** Pattern3 ::= InfixPattern [‘*’]
2631+ /** Pattern3 ::= InfixPattern
2632+ * | PatVar ‘*’
26322633 */
26332634 def pattern3 (): Tree =
26342635 val p = infixPattern()
26352636 if followingIsVararg() then
26362637 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
26382644 }
26392645 else p
26402646
@@ -2726,7 +2732,7 @@ object Parsers {
27262732 if (in.token == RPAREN ) Nil else patterns(location)
27272733
27282734 /** ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
2729- * | ‘(’ [Patterns ‘,’] Pattern2 ‘*’ ‘)’
2735+ * | ‘(’ [Patterns ‘,’] PatVar ‘*’ ‘)’
27302736 */
27312737 def argumentPatterns (): List [Tree ] =
27322738 inParens(patternsOpt(Location .InPatternArgs ))
Original file line number Diff line number Diff line change @@ -296,7 +296,7 @@ PatVar ::= varid
296296 | ‘_’
297297Patterns ::= Pattern {‘,’ Pattern}
298298ArgumentPatterns ::= ‘(’ [Patterns] ‘)’ Apply(fn, pats)
299- | ‘(’ [Patterns ‘,’] Pattern2 ‘*’ ‘)’
299+ | ‘(’ [Patterns ‘,’] PatVar ‘*’ ‘)’
300300```
301301
302302### Type and Value Parameters
Original file line number Diff line number Diff line change @@ -290,7 +290,7 @@ PatVar ::= varid
290290 | ‘_’
291291Patterns ::= Pattern {‘,’ Pattern}
292292ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
293- | ‘(’ [Patterns ‘,’] Pattern2 ‘*’ ‘)’
293+ | ‘(’ [Patterns ‘,’] PatVar ‘*’ ‘)’
294294```
295295
296296### 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