diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-06-03 10:06:59 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-06-03 10:06:59 -0700 |
commit | 6ed018b2e9ca4bf0696f9d692d93a67d6bad4c5f (patch) | |
tree | f0b6a44c54b799f746af9f97260c2c6cff606013 /test/files | |
parent | 488ed391e3572a621d7692c604fad464346091a5 (diff) | |
parent | 3cb72faace500c14017cc163411dcac36a4ba9a4 (diff) | |
download | scala-6ed018b2e9ca4bf0696f9d692d93a67d6bad4c5f.tar.gz scala-6ed018b2e9ca4bf0696f9d692d93a67d6bad4c5f.tar.bz2 scala-6ed018b2e9ca4bf0696f9d692d93a67d6bad4c5f.zip |
Merge pull request #650 from adriaanm/topic-virtpatmat
Unreachability analysis for pattern matches
Thanks for reviewing, @retronym!
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/neg/patmatexhaust.check | 5 | ||||
-rw-r--r-- | test/files/neg/virtpatmat_reach_null.check | 4 | ||||
-rw-r--r-- | test/files/neg/virtpatmat_reach_null.flags | 1 | ||||
-rw-r--r-- | test/files/neg/virtpatmat_reach_null.scala | 19 | ||||
-rw-r--r-- | test/files/neg/virtpatmat_reach_sealed_unsealed.check | 14 | ||||
-rw-r--r-- | test/files/neg/virtpatmat_reach_sealed_unsealed.flags | 1 | ||||
-rw-r--r-- | test/files/neg/virtpatmat_reach_sealed_unsealed.scala | 21 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_reach_const.scala | 11 |
8 files changed, 75 insertions, 1 deletions
diff --git a/test/files/neg/patmatexhaust.check b/test/files/neg/patmatexhaust.check index 1168f36e11..4556e6622f 100644 --- a/test/files/neg/patmatexhaust.check +++ b/test/files/neg/patmatexhaust.check @@ -14,6 +14,9 @@ patmatexhaust.scala:49: error: match may not be exhaustive. It would fail on the following inputs: Gp(), Gu def ma4(x:Deep) = x match { // missing cases: Gu, Gp ^ +patmatexhaust.scala:55: error: unreachable code + case _ if 1 == 0 => + ^ patmatexhaust.scala:53: error: match may not be exhaustive. It would fail on the following input: Gp() def ma5(x:Deep) = x match { @@ -34,4 +37,4 @@ patmatexhaust.scala:126: error: match may not be exhaustive. It would fail on the following input: C1() def ma10(x: C) = x match { // not exhaustive: C1 is not abstract. ^ -9 errors found +10 errors found diff --git a/test/files/neg/virtpatmat_reach_null.check b/test/files/neg/virtpatmat_reach_null.check new file mode 100644 index 0000000000..595c8ec889 --- /dev/null +++ b/test/files/neg/virtpatmat_reach_null.check @@ -0,0 +1,4 @@ +virtpatmat_reach_null.scala:13: error: unreachable code + case _ => // unreachable + ^ +one error found diff --git a/test/files/neg/virtpatmat_reach_null.flags b/test/files/neg/virtpatmat_reach_null.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/neg/virtpatmat_reach_null.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/virtpatmat_reach_null.scala b/test/files/neg/virtpatmat_reach_null.scala new file mode 100644 index 0000000000..6314a5b1d8 --- /dev/null +++ b/test/files/neg/virtpatmat_reach_null.scala @@ -0,0 +1,19 @@ +sealed abstract class Const { + final def excludes(other: Const) = + (this, other) match { + case (_, NullConst) => + case (NullConst, _) => + case (_: ValueConst, _: ValueConst) => + case (_: ValueConst, _: TypeConst) => + case (_: TypeConst, _: ValueConst) => + case (_: TypeConst, _: TypeConst) => + case (null, _) => + case (_, null) => + case null => + case _ => // unreachable + } +} + +sealed class TypeConst extends Const +sealed class ValueConst extends Const +case object NullConst extends Const diff --git a/test/files/neg/virtpatmat_reach_sealed_unsealed.check b/test/files/neg/virtpatmat_reach_sealed_unsealed.check new file mode 100644 index 0000000000..10638eff52 --- /dev/null +++ b/test/files/neg/virtpatmat_reach_sealed_unsealed.check @@ -0,0 +1,14 @@ +virtpatmat_reach_sealed_unsealed.scala:16: error: match may not be exhaustive. +It would fail on the following input: false + (true: Boolean) match { case true => } // not exhaustive, but reachable + ^ +virtpatmat_reach_sealed_unsealed.scala:18: error: unreachable code + (true: Boolean) match { case true => case false => case _ => } // exhaustive, last case is unreachable + ^ +virtpatmat_reach_sealed_unsealed.scala:19: error: unreachable code + (true: Boolean) match { case true => case false => case _: Boolean => } // exhaustive, last case is unreachable + ^ +virtpatmat_reach_sealed_unsealed.scala:20: error: unreachable code + (true: Boolean) match { case true => case false => case _: Any => } // exhaustive, last case is unreachable + ^ +four errors found diff --git a/test/files/neg/virtpatmat_reach_sealed_unsealed.flags b/test/files/neg/virtpatmat_reach_sealed_unsealed.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/neg/virtpatmat_reach_sealed_unsealed.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/virtpatmat_reach_sealed_unsealed.scala b/test/files/neg/virtpatmat_reach_sealed_unsealed.scala new file mode 100644 index 0000000000..13911dbd78 --- /dev/null +++ b/test/files/neg/virtpatmat_reach_sealed_unsealed.scala @@ -0,0 +1,21 @@ +sealed abstract class X +sealed case class A(x: Int) extends X + +// test reachability on mixed sealed / non-sealed matches +object Test extends App { + val B: X = A(0) + val C: X = A(1) + + // all cases are reachable and the match is exhaustive + (C: X) match { + case B => + case C => + case A(_) => + } + + (true: Boolean) match { case true => } // not exhaustive, but reachable + (true: Boolean) match { case true => case false => } // exhaustive, reachable + (true: Boolean) match { case true => case false => case _ => } // exhaustive, last case is unreachable + (true: Boolean) match { case true => case false => case _: Boolean => } // exhaustive, last case is unreachable + (true: Boolean) match { case true => case false => case _: Any => } // exhaustive, last case is unreachable +}
\ No newline at end of file diff --git a/test/files/pos/virtpatmat_reach_const.scala b/test/files/pos/virtpatmat_reach_const.scala new file mode 100644 index 0000000000..b55b7cb229 --- /dev/null +++ b/test/files/pos/virtpatmat_reach_const.scala @@ -0,0 +1,11 @@ +// check the interaction between constants and type tests in creating the equality axioms +object Test { + type Formula = List[String] + val TrueF: Formula = List() + def distribute(a: Formula, b: Formula) = (a, b) match { + case (TrueF, _) => + case (_, TrueF) => // bug: considered unreachable + case (a :: Nil, b :: Nil) => + case _ => + } +}
\ No newline at end of file |