Skip to content

Commit 3c8461e

Browse files
committed
Allow infix types in typed patterns
Previously, we parsed x: A | B as (x: A) | B but this is silly, since the binding of `x` would be illegal anyway. So we now parse it as x: (A | B)
1 parent 8c2e2e0 commit 3c8461e

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ object Parsers {
976976

977977
def typeDependingOn(location: Location.Value): Tree =
978978
if (location == Location.InParens) typ()
979-
else if (location == Location.InPattern) refinedType()
979+
else if (location == Location.InPattern) infixType()
980980
else infixType()
981981

982982
/** Checks whether `t` is a wildcard type.

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ CaseClauses ::= CaseClause { CaseClause }
218218
CaseClause ::= ‘case’ (Pattern [Guard] ‘=>’ Block | INT)
219219
220220
Pattern ::= Pattern1 { ‘|’ Pattern1 } Alternative(pats)
221-
Pattern1 ::= PatVar ‘:’ RefinedType Bind(name, Typed(Ident(wildcard), tpe))
221+
Pattern1 ::= PatVar ‘:’ InfixType Bind(name, Typed(Ident(wildcard), tpe))
222222
| Pattern2
223223
Pattern2 ::= [id ‘@’] InfixPattern Bind(name, pat)
224224
InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat)

0 commit comments

Comments
 (0)