diff options
author | Paul Phillips <paulp@improving.org> | 2013-01-25 08:13:02 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-01-25 08:13:02 -0800 |
commit | b49eaefd816a80ad7d04b150c16f8e76cfbdb03e (patch) | |
tree | e06b1f3afd4266ec1078bc136ce6e274be746a2e /src/compiler | |
parent | 5e2821caef2f49185338c01a7cb8a4e5e0155b7a (diff) | |
parent | cbd0205999d19e378f9f7ac8ca685a134862cf47 (diff) | |
download | scala-b49eaefd816a80ad7d04b150c16f8e76cfbdb03e.tar.gz scala-b49eaefd816a80ad7d04b150c16f8e76cfbdb03e.tar.bz2 scala-b49eaefd816a80ad7d04b150c16f8e76cfbdb03e.zip |
Merge pull request #1928 from retronym/ticket/6902
SI-6902 Check unreachability under @unchecked
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala index cdceb2d992..69bbab6e42 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala @@ -3244,6 +3244,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL // TODO: make more fine-grained, as we don't always need to jump def canJump: Boolean + /** Should exhaustivity analysis be skipped? */ def unchecked: Boolean @@ -3477,12 +3478,10 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL case Some(cds) => cds } - val allReachable = unchecked || { - // a switch with duplicate cases yields a verify error, - // and a switch with duplicate cases and guards cannot soundly be rewritten to an unguarded switch - // (even though the verify error would disappear, the behaviour would change) - unreachableCase(caseDefsWithGuards) map (cd => reportUnreachable(cd.body.pos)) isEmpty - } + // a switch with duplicate cases yields a verify error, + // and a switch with duplicate cases and guards cannot soundly be rewritten to an unguarded switch + // (even though the verify error would disappear, the behaviour would change) + val allReachable = unreachableCase(caseDefsWithGuards) map (cd => reportUnreachable(cd.body.pos)) isEmpty if (!allReachable) Nil else if (noGuards(caseDefsWithGuards)) { @@ -3731,10 +3730,10 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL with SymbolicMatchAnalysis with DPLLSolver { self: TreeMakers => override def optimizeCases(prevBinder: Symbol, cases: List[List[TreeMaker]], pt: Type, unchecked: Boolean): (List[List[TreeMaker]], List[Tree]) = { + unreachableCase(prevBinder, cases, pt) foreach { caseIndex => + reportUnreachable(cases(caseIndex).last.pos) + } if (!unchecked) { - unreachableCase(prevBinder, cases, pt) foreach { caseIndex => - reportUnreachable(cases(caseIndex).last.pos) - } val counterExamples = exhaustive(prevBinder, cases, pt) if (counterExamples.nonEmpty) reportMissingCases(prevBinder.pos, counterExamples) |