From c1aa83b904354335e38e1574720ebe36b57e34dc Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 19 Aug 2021 15:25:09 +0200 Subject: [PATCH 1/2] Allow semicolon between type match cases Fixes #13331 --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 3 ++- docs/docs/internals/syntax.md | 2 +- docs/docs/reference/syntax.md | 2 +- tests/pos/i13331.scala | 3 +++ 4 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i13331.scala 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/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 From 1630823429c9d98e6b5173b1c9010694b8574fe3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 23 Aug 2021 11:36:29 +0200 Subject: [PATCH 2/2] Move neg test to pos --- tests/{neg => pos}/case-semi.scala | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{neg => pos}/case-semi.scala (100%) 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