Skip to content

Fix #2363: better handle extractors in exhaustivity check #2424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 16, 2017
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ object desugar {
case IdPattern(named, tpt) =>
Function(derivedValDef(pat, named, tpt, EmptyTree, Modifiers(Param)) :: Nil, body)
case _ =>
makeCaseLambda(CaseDef(pat, EmptyTree, body) :: Nil, unchecked = false)
makeCaseLambda(CaseDef(pat, EmptyTree, body) :: Nil)
}

/** If `pat` is not an Identifier, a Typed(Ident, _), or a Bind, wrap
Expand Down
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,17 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {
/* (Nil, body) means that `body` is the default case
* It's a bit hacky but it simplifies manipulations.
*/
def extractSwitchCase(treeMakers: List[TreeMaker]): (List[Int], BodyTreeMaker) = treeMakers match {
def extractSwitchCase(treeMakers: List[TreeMaker]): (List[Int], BodyTreeMaker) = (treeMakers: @unchecked) match {
// case 5 =>
case List(IntEqualityTestTreeMaker(intValue), body: BodyTreeMaker) =>
(List(intValue), body)

// case 5 | 6 =>
case List(AlternativesTreeMaker(_, alts, _), body: BodyTreeMaker) =>
val intValues = alts.map {
case List(IntEqualityTestTreeMaker(intValue)) => intValue
val intValues = alts.map { alt =>
(alt: @unchecked) match {
case List(IntEqualityTestTreeMaker(intValue)) => intValue
}
}
(intValues, body)

Expand Down
Loading