diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-06-08 17:52:36 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-06-09 14:55:49 +0200 |
commit | 97c338353dc0e83d93498ec486afbcff2aa9e931 (patch) | |
tree | ed9a53503f16c8a5a61a3a54ce035f01e2f8163b /test/files | |
parent | 43ae8259f2e01393219d1ece0c87614eece32621 (diff) | |
download | scala-97c338353dc0e83d93498ec486afbcff2aa9e931.tar.gz scala-97c338353dc0e83d93498ec486afbcff2aa9e931.tar.bz2 scala-97c338353dc0e83d93498ec486afbcff2aa9e931.zip |
better unreachability for selections
Consts are hashconsed modulo static-approximation-for-dynamic-value-equality
thus, two value-equality tests in patterns should reuse the same ValueConst
if and only if the tested values are guaranteed to be equal in all possible executions
the implementation uses unique types to track unique consts
for an Ident with a stable symbol, we simply use the corresponding singleton type
for a Select, we have to indirect some more: we store all the unique trees we've encountered and a unique type for each of them
this unique type is then used to find the uniqut const that approximates the run-time value
this may seem roundabout, but we need to standardize on types for representing "value" tests,
as a type test against a singleton type must give rise to the same ValueConst
as a value test using a tree that refers to the same symbol as the singleton type test
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/neg/virtpatmat_unreach_select.check | 4 | ||||
-rw-r--r-- | test/files/neg/virtpatmat_unreach_select.flags | 1 | ||||
-rw-r--r-- | test/files/neg/virtpatmat_unreach_select.scala | 12 |
3 files changed, 17 insertions, 0 deletions
diff --git a/test/files/neg/virtpatmat_unreach_select.check b/test/files/neg/virtpatmat_unreach_select.check new file mode 100644 index 0000000000..3771971020 --- /dev/null +++ b/test/files/neg/virtpatmat_unreach_select.check @@ -0,0 +1,4 @@ +virtpatmat_unreach_select.scala:10: error: unreachable code + case WARNING.id => // unreachable + ^ +one error found diff --git a/test/files/neg/virtpatmat_unreach_select.flags b/test/files/neg/virtpatmat_unreach_select.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/neg/virtpatmat_unreach_select.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/neg/virtpatmat_unreach_select.scala b/test/files/neg/virtpatmat_unreach_select.scala new file mode 100644 index 0000000000..c46ff15453 --- /dev/null +++ b/test/files/neg/virtpatmat_unreach_select.scala @@ -0,0 +1,12 @@ +class Test { + object severity extends Enumeration + class Severity(val id: Int) extends severity.Value + val INFO = new Severity(0) + val WARNING = new Severity(1) + + (0: Int) match { + case WARNING.id => + case INFO.id => // reachable + case WARNING.id => // unreachable + } +} |