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 @@ -2594,12 +2594,19 @@ object Parsers {
25942594 })
25952595 }
25962596
2597- /** TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
2597+ /** TypeCaseClause ::= ‘case’ ( InfixType | ‘_’) ‘=>’ Type [nl]
25982598 */
25992599 def typeCaseClause (): CaseDef = atSpan(in.offset) {
26002600 val pat = inSepRegion(InCase ) {
26012601 accept(CASE )
2602- infixType()
2602+ in.token match {
2603+ case USCORE if in.lookahead.isArrow =>
2604+ val start = in.skipToken()
2605+ typeBounds().withSpan(Span (start, in.lastOffset, start))
2606+
2607+ case _ =>
2608+ infixType()
2609+ }
26032610 }
26042611 CaseDef (pat, EmptyTree , atSpan(accept(ARROW )) {
26052612 val t = typ()
Original file line number Diff line number Diff line change @@ -286,7 +286,7 @@ CaseClauses ::= CaseClause { CaseClause }
286286CaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Block CaseDef(pat, guard?, block) // block starts at =>
287287ExprCaseClause ::= ‘case’ Pattern [Guard] ‘=>’ Expr
288288TypeCaseClauses ::= TypeCaseClause { TypeCaseClause }
289- TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
289+ TypeCaseClause ::= ‘case’ ( InfixType | ‘_’) ‘=>’ Type [nl]
290290
291291Pattern ::= Pattern1 { ‘|’ Pattern1 } Alternative(pats)
292292Pattern1 ::= 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