Skip to content

Commit 391c0f7

Browse files
committed
Support generalized case x @ pat => in switches.
1 parent 2492d70 commit 391c0f7

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,14 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
339339
case List(_: BodyTreeMaker) =>
340340
true
341341

342-
// case x =>
343-
case List(_: SubstOnlyTreeMaker, _: BodyTreeMaker) =>
344-
true
342+
/* case x @ pat =>
343+
* This includes:
344+
* case x =>
345+
* case x @ 5 =>
346+
* case x @ (5 | 6) =>
347+
*/
348+
case (_: SubstOnlyTreeMaker) :: rest =>
349+
isSwitchCase(rest)
345350

346351
case _ =>
347352
false
@@ -366,12 +371,13 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
366371
case List(body: BodyTreeMaker) =>
367372
(Nil, body)
368373

369-
// case x =>
370-
case List(subst: SubstOnlyTreeMaker, body: BodyTreeMaker) =>
371-
/* Rebindings have been propagated, so `body` contains all the
372-
* necessary information. `subst` can be dropped at this point.
374+
// case x @ pat =>
375+
case (_: SubstOnlyTreeMaker) :: rest =>
376+
/* Rebindings have been propagated, so the eventual body in `rest`
377+
* contains all the necessary information. The substitution can be
378+
* dropped at this point.
373379
*/
374-
(Nil, body)
380+
extractSwitchCase(rest)
375381
}
376382

377383
def doOverlap(a: List[Int], b: List[Int]): Boolean =

0 commit comments

Comments
 (0)