summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-10-05 15:34:37 +0000
committerPaul Phillips <paulp@improving.org>2010-10-05 15:34:37 +0000
commit7553e6901d52ace00bfcb670336c480766c8301c (patch)
tree720e9fa758661c6d5cc51340b4b693433d00d696 /src
parenta4cf7b1ec5dade69b41e59469b9b3f65415b9822 (diff)
downloadscala-7553e6901d52ace00bfcb670336c480766c8301c.tar.gz
scala-7553e6901d52ace00bfcb670336c480766c8301c.tar.bz2
scala-7553e6901d52ace00bfcb670336c480766c8301c.zip
Improves exhaustiveness analysis to not warn ab...
Improves exhaustiveness analysis to not warn about types which cannot match due to nonconformant type parameters. Also, look at the different warnings emitted in the test case based on the presence of a constraint. Nifty! Closes #3683, no review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala b/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala
index 6141b2333c..b880dea858 100644
--- a/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala
+++ b/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala
@@ -173,19 +173,24 @@ trait MatrixAdditions extends ast.TreeDSL
private def rowCoversCombo(row: Row, combos: List[Combo]) =
row.guard.isEmpty && (combos forall (c => c isCovered row.pats(c.index)))
- private def requiresExhaustive(s: Symbol) = {
- (s hasFlag MUTABLE) && // indicates that have not yet checked exhaustivity
- !(s hasFlag TRANS_FLAG) && // indicates @unchecked
- (s.tpe.typeSymbol.isSealed) && {
- s resetFlag MUTABLE // side effects MUTABLE flag
- !isValueClass(s.tpe.typeSymbol) // but make sure it's not a primitive, else (5: Byte) match { case 5 => ... } sees no Byte
- }
+ private def requiresExhaustive(sym: Symbol) = {
+ (sym.isMutable) && // indicates that have not yet checked exhaustivity
+ !(sym hasFlag TRANS_FLAG) && // indicates @unchecked
+ (sym.tpe.typeSymbol.isSealed) &&
+ !isValueClass(sym.tpe.typeSymbol) // make sure it's not a primitive, else (5: Byte) match { case 5 => ... } sees no Byte
}
private lazy val inexhaustives: List[List[Combo]] = {
- val collected =
- for ((pv, i) <- tvars.zipWithIndex ; val sym = pv.lhs ; if requiresExhaustive(sym)) yield
- i -> sym.tpe.typeSymbol.sealedDescendants
+ // let's please not get too clever side-effecting the mutable flag.
+ val toCollect = tvars.zipWithIndex filter { case (pv, i) => requiresExhaustive(pv.sym) }
+ val collected = toCollect map { case (pv, i) =>
+ // okay, now reset the flag
+ pv.sym resetFlag MUTABLE
+ // have to filter out children which cannot match: see ticket #3683 for an example
+ val kids = pv.tpe.typeSymbol.sealedDescendants filter (_.tpe matchesPattern pv.tpe)
+
+ i -> kids
+ }
val folded =
collected.foldRight(List[List[Combo]]())((c, xs) => {