Skip to content

Commit 6922c1d

Browse files
authored
Merge pull request #13338 from dotty-staging/fix-13331
Allow semicolon between type match cases
2 parents 4958012 + 1630823 commit 6922c1d

File tree

5 files changed

+7
-3
lines changed

5 files changed

+7
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2604,7 +2604,7 @@ object Parsers {
26042604
})
26052605
}
26062606

2607-
/** TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
2607+
/** TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [semi]
26082608
*/
26092609
def typeCaseClause(): CaseDef = atSpan(in.offset) {
26102610
val pat = inSepRegion(InCase) {
@@ -2613,6 +2613,7 @@ object Parsers {
26132613
}
26142614
CaseDef(pat, EmptyTree, atSpan(accept(ARROW)) {
26152615
val t = typ()
2616+
if in.token == SEMI then in.nextToken()
26162617
newLinesOptWhenFollowedBy(CASE)
26172618
t
26182619
})

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ CaseClauses ::= CaseClause { CaseClause }
287287
CaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Block CaseDef(pat, guard?, block) // block starts at =>
288288
ExprCaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Expr
289289
TypeCaseClauses ::= TypeCaseClause { TypeCaseClause }
290-
TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
290+
TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [semi]
291291
292292
Pattern ::= Pattern1 { ‘|’ Pattern1 } Alternative(pats)
293293
Pattern1 ::= Pattern2 [‘:’ RefinedType] Bind(name, Typed(Ident(wildcard), tpe))

docs/docs/reference/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ CaseClauses ::= CaseClause { CaseClause }
279279
CaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Block
280280
ExprCaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Expr
281281
TypeCaseClauses ::= TypeCaseClause { TypeCaseClause }
282-
TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
282+
TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [semi]
283283
284284
Pattern ::= Pattern1 { ‘|’ Pattern1 }
285285
Pattern1 ::= Pattern2 [‘:’ RefinedType]
File renamed without changes.

tests/pos/i13331.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def Choice = (_: Any) match { case Int => Long; case Long => Int } // ok
2+
3+
type Choice[A] = A match { case Int => Long ; case Long => Int } // error

0 commit comments

Comments
 (0)