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 @@ -2574,12 +2574,19 @@ object Parsers {
25742574 })
25752575 }
25762576
2577- /** TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
2577+ /** TypeCaseClause ::= ‘case’ ( InfixType | ‘_’) ‘=>’ Type [nl]
25782578 */
25792579 def typeCaseClause (): CaseDef = atSpan(in.offset) {
25802580 val pat = inSepRegion(InCase ) {
25812581 accept(CASE )
2582- infixType()
2582+ in.token match {
2583+ case USCORE if in.lookahead.isArrow =>
2584+ val start = in.skipToken()
2585+ typeBounds().withSpan(Span (start, in.lastOffset, start))
2586+
2587+ case _ =>
2588+ infixType()
2589+ }
25832590 }
25842591 CaseDef (pat, EmptyTree , atSpan(accept(ARROW )) {
25852592 val t = typ()
Original file line number Diff line number Diff line change @@ -285,7 +285,7 @@ CaseClauses ::= CaseClause { CaseClause }
285285CaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Block CaseDef(pat, guard?, block) // block starts at =>
286286ExprCaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Expr
287287TypeCaseClauses ::= TypeCaseClause { TypeCaseClause }
288- TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
288+ TypeCaseClause ::= ‘case’ ( InfixType | ‘_’) ‘=>’ Type [nl]
289289
290290Pattern ::= Pattern1 { ‘|’ Pattern1 } Alternative(pats)
291291Pattern1 ::= 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