diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 399eabfff0f1..280b9e611b60 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2604,7 +2604,7 @@ object Parsers { }) } - /** TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl] + /** TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [semi] */ def typeCaseClause(): CaseDef = atSpan(in.offset) { val pat = inSepRegion(InCase) { @@ -2613,6 +2613,7 @@ object Parsers { } CaseDef(pat, EmptyTree, atSpan(accept(ARROW)) { val t = typ() + if in.token == SEMI then in.nextToken() newLinesOptWhenFollowedBy(CASE) t }) diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index f3f60dc50a13..307642ee81d8 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -287,7 +287,7 @@ CaseClauses ::= CaseClause { CaseClause } CaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Block CaseDef(pat, guard?, block) // block starts at => ExprCaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Expr TypeCaseClauses ::= TypeCaseClause { TypeCaseClause } -TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl] +TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [semi] Pattern ::= Pattern1 { ‘|’ Pattern1 } Alternative(pats) Pattern1 ::= Pattern2 [‘:’ RefinedType] Bind(name, Typed(Ident(wildcard), tpe)) diff --git a/docs/docs/reference/syntax.md b/docs/docs/reference/syntax.md index ecb44ef35b2e..d802e05cb4f2 100644 --- a/docs/docs/reference/syntax.md +++ b/docs/docs/reference/syntax.md @@ -279,7 +279,7 @@ CaseClauses ::= CaseClause { CaseClause } CaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Block ExprCaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Expr TypeCaseClauses ::= TypeCaseClause { TypeCaseClause } -TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl] +TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [semi] Pattern ::= Pattern1 { ‘|’ Pattern1 } Pattern1 ::= Pattern2 [‘:’ RefinedType] diff --git a/tests/neg/case-semi.scala b/tests/pos/case-semi.scala similarity index 100% rename from tests/neg/case-semi.scala rename to tests/pos/case-semi.scala diff --git a/tests/pos/i13331.scala b/tests/pos/i13331.scala new file mode 100644 index 000000000000..d862898eaa04 --- /dev/null +++ b/tests/pos/i13331.scala @@ -0,0 +1,3 @@ +def Choice = (_: Any) match { case Int => Long; case Long => Int } // ok + +type Choice[A] = A match { case Int => Long ; case Long => Int } // error \ No newline at end of file