@@ -1666,7 +1666,7 @@ object Parsers {
16661666 if in.token == LPAREN then funParamClause() :: funParamClauses() else Nil
16671667
16681668 /** InfixType ::= RefinedType {id [nl] RefinedType}
1669- * | RefinedType `^`
1669+ * | RefinedType `^` // under capture checking
16701670 */
16711671 def infixType (): Tree = infixTypeRest(refinedType())
16721672
@@ -2881,13 +2881,13 @@ object Parsers {
28812881 if (isIdent(nme.raw.BAR )) { in.nextToken(); pattern1(location) :: patternAlts(location) }
28822882 else Nil
28832883
2884- /** Pattern1 ::= PatVar Ascription
2885- * | [‘-’] integerLiteral Ascription
2886- * | [‘-’] floatingPointLiteral Ascription
2884+ /** Pattern1 ::= PatVar `:` RefinedType
2885+ * | [‘-’] integerLiteral `:` RefinedType
2886+ * | [‘-’] floatingPointLiteral `:` RefinedType
28872887 * | Pattern2
28882888 */
28892889 def pattern1 (location : Location = Location .InPattern ): Tree =
2890- val p = pattern2()
2890+ val p = pattern2(location )
28912891 if in.isColon then
28922892 val isVariableOrNumber = isVarPattern(p) || p.isInstanceOf [Number ]
28932893 if ! isVariableOrNumber then
@@ -2905,26 +2905,29 @@ object Parsers {
29052905 else p
29062906
29072907 /** Pattern3 ::= InfixPattern
2908- * | PatVar ‘*’
29092908 */
2910- def pattern3 (): Tree =
2909+ def pattern3 (location : Location ): Tree =
29112910 val p = infixPattern()
29122911 if followingIsVararg() then
29132912 val start = in.skipToken()
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
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
29202923 else p
29212924
29222925 /** Pattern2 ::= [id `@'] Pattern3
29232926 */
2924- val pattern2 : () => Tree = () => pattern3() match
2927+ val pattern2 : Location => Tree = location => pattern3(location ) match
29252928 case p @ Ident (name) if in.token == AT =>
29262929 val offset = in.skipToken()
2927- pattern3() match {
2930+ pattern3(location ) match {
29282931 case pt @ Bind (nme.WILDCARD , pt1 : Typed ) if pt.mods.is(Given ) =>
29292932 atSpan(startOffset(p), 0 ) { Bind (name, pt1).withMods(pt.mods) }
29302933 case Typed (Ident (nme.WILDCARD ), pt @ Ident (tpnme.WILDCARD_STAR )) =>
@@ -2954,6 +2957,7 @@ object Parsers {
29542957 * | XmlPattern
29552958 * | `(' [Patterns] `)'
29562959 * | SimplePattern1 [TypeArgs] [ArgumentPatterns]
2960+ * | ‘given’ RefinedType
29572961 * SimplePattern1 ::= SimpleRef
29582962 * | SimplePattern1 `.' id
29592963 * PatVar ::= id
@@ -3597,7 +3601,7 @@ object Parsers {
35973601 * VarDcl ::= id {`,' id} `:' Type
35983602 */
35993603 def patDefOrDcl (start : Offset , mods : Modifiers ): Tree = atSpan(start, nameStart) {
3600- val first = pattern2()
3604+ val first = pattern2(Location . InPattern )
36013605 var lhs = first match {
36023606 case id : Ident if in.token == COMMA =>
36033607 in.nextToken()
0 commit comments