File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -2607,12 +2607,19 @@ object Parsers {
2607
2607
})
2608
2608
}
2609
2609
2610
- /** TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [semi]
2610
+ /** TypeCaseClause ::= ‘case’ ( InfixType | ‘_’) ‘=>’ Type [semi]
2611
2611
*/
2612
2612
def typeCaseClause (): CaseDef = atSpan(in.offset) {
2613
2613
val pat = inSepRegion(InCase ) {
2614
2614
accept(CASE )
2615
- infixType()
2615
+ in.token match {
2616
+ case USCORE if in.lookahead.isArrow =>
2617
+ val start = in.skipToken()
2618
+ typeBounds().withSpan(Span (start, in.lastOffset, start))
2619
+
2620
+ case _ =>
2621
+ infixType()
2622
+ }
2616
2623
}
2617
2624
CaseDef (pat, EmptyTree , atSpan(accept(ARROW )) {
2618
2625
val t = typ()
Original file line number Diff line number Diff line change @@ -289,7 +289,7 @@ CaseClauses ::= CaseClause { CaseClause }
289
289
CaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Block CaseDef(pat, guard?, block) // block starts at =>
290
290
ExprCaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Expr
291
291
TypeCaseClauses ::= TypeCaseClause { TypeCaseClause }
292
- TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [semi]
292
+ TypeCaseClause ::= ‘case’ ( InfixType | ‘_’) ‘=>’ Type [semi]
293
293
294
294
Pattern ::= Pattern1 { ‘|’ Pattern1 } Alternative(pats)
295
295
Pattern1 ::= Pattern2 [‘:’ RefinedType] Bind(name, Typed(Ident(wildcard), tpe))
Original file line number Diff line number Diff line change
1
+ // `case _ => expr` in a match expression should be equivalant to
2
+ // `case _: Any => expr`. Likewise, in a match type, `case _ => T`
3
+ // should be equivalant to `case Any => T`.
4
+
5
+ object Test0 {
6
+ type M [X ] = X match { case String => Int case Any => String }
7
+ def m [X ](x : X ): M [X ] = x match { case _ : String => 1 case _ : Any => " s" }
8
+ }
9
+
10
+ object Test2 {
11
+ type M [X ] = X match { case String => Int case _ => String }
12
+ def m [X ](x : X ): M [X ] = x match { case _ : String => 1 case _ : Any => " s" }
13
+ }
You can’t perform that action at this time.
0 commit comments