diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 3079b26df6cd..d76cf6c2eb92 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1665,7 +1665,7 @@ object Parsers { if in.token == LPAREN then funParamClause() :: funParamClauses() else Nil /** InfixType ::= RefinedType {id [nl] RefinedType} - * | RefinedType `^` + * | RefinedType `^` // under capture checking */ def infixType(): Tree = infixTypeRest(refinedType()) @@ -2855,13 +2855,13 @@ object Parsers { if (isIdent(nme.raw.BAR)) { in.nextToken(); pattern1(location) :: patternAlts(location) } else Nil - /** Pattern1 ::= PatVar Ascription - * | [‘-’] integerLiteral Ascription - * | [‘-’] floatingPointLiteral Ascription + /** Pattern1 ::= PatVar `:` RefinedType + * | [‘-’] integerLiteral `:` RefinedType + * | [‘-’] floatingPointLiteral `:` RefinedType * | Pattern2 */ def pattern1(location: Location = Location.InPattern): Tree = - val p = pattern2() + val p = pattern2(location) if in.isColon then val isVariableOrNumber = isVarPattern(p) || p.isInstanceOf[Number] if !isVariableOrNumber then @@ -2879,11 +2879,10 @@ object Parsers { else p /** Pattern3 ::= InfixPattern - * | PatVar ‘*’ */ - def pattern3(): Tree = + def pattern3(location: Location): Tree = val p = infixPattern() - if followingIsVararg() then + if location.inArgs && followingIsVararg() then val start = in.skipToken() p match case p @ Ident(name) if name.isVarPattern => @@ -2895,10 +2894,10 @@ object Parsers { /** Pattern2 ::= [id `@'] Pattern3 */ - val pattern2: () => Tree = () => pattern3() match + val pattern2: Location => Tree = location => pattern3(location) match case p @ Ident(name) if in.token == AT => val offset = in.skipToken() - pattern3() match { + pattern3(location) match { case pt @ Bind(nme.WILDCARD, pt1: Typed) if pt.mods.is(Given) => atSpan(startOffset(p), 0) { Bind(name, pt1).withMods(pt.mods) } case Typed(Ident(nme.WILDCARD), pt @ Ident(tpnme.WILDCARD_STAR)) => @@ -2928,6 +2927,7 @@ object Parsers { * | XmlPattern * | `(' [Patterns] `)' * | SimplePattern1 [TypeArgs] [ArgumentPatterns] + * | ‘given’ RefinedType * SimplePattern1 ::= SimpleRef * | SimplePattern1 `.' id * PatVar ::= id @@ -3569,7 +3569,7 @@ object Parsers { * VarDcl ::= id {`,' id} `:' Type */ def patDefOrDcl(start: Offset, mods: Modifiers): Tree = atSpan(start, nameStart) { - val first = pattern2() + val first = pattern2(Location.InPattern) var lhs = first match { case id: Ident if in.token == COMMA => in.nextToken() diff --git a/docs/_docs/internals/syntax.md b/docs/_docs/internals/syntax.md index 2817a7477b10..c37a945aa614 100644 --- a/docs/_docs/internals/syntax.md +++ b/docs/_docs/internals/syntax.md @@ -318,7 +318,7 @@ Pattern1 ::= PatVar ‘:’ RefinedType | [‘-’] integerLiteral ‘:’ RefinedType Typed(pat, tpe) | [‘-’] floatingPointLiteral ‘:’ RefinedType Typed(pat, tpe) | Pattern2 -Pattern2 ::= [id ‘@’] InfixPattern [‘*’] Bind(name, pat) +Pattern2 ::= [id ‘@’] InfixPattern Bind(name, pat) InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat) SimplePattern ::= PatVar Ident(wildcard) | Literal Bind(name, Ident(wildcard)) @@ -357,8 +357,8 @@ ClsParam ::= {Annotation} [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param DefParamClauses ::= DefParamClause { DefParamClause } -- and two DefTypeParamClause cannot be adjacent -DefParamClause ::= DefTypeParamClause - | DefTermParamClause +DefParamClause ::= DefTypeParamClause + | DefTermParamClause | UsingParamClause TypelessClauses ::= TypelessClause {TypelessClause} TypelessClause ::= DefTermParamClause diff --git a/docs/_docs/reference/syntax.md b/docs/_docs/reference/syntax.md index a705c5a3fd79..cef62e63da45 100644 --- a/docs/_docs/reference/syntax.md +++ b/docs/_docs/reference/syntax.md @@ -316,7 +316,7 @@ Pattern1 ::= PatVar ‘:’ RefinedType | [‘-’] integerLiteral ‘:’ RefinedType | [‘-’] floatingPointLiteral ‘:’ RefinedType | Pattern2 -Pattern2 ::= [id ‘@’] InfixPattern [‘*’] +Pattern2 ::= [id ‘@’] InfixPattern InfixPattern ::= SimplePattern { id [nl] SimplePattern } SimplePattern ::= PatVar | Literal diff --git a/tests/neg/i17443.scala b/tests/neg/i17443.scala new file mode 100644 index 000000000000..95e963b6a1d9 --- /dev/null +++ b/tests/neg/i17443.scala @@ -0,0 +1,2 @@ +def run() = + val x = List(1) match { case (xs*) => xs } // error