From 97c338353dc0e83d93498ec486afbcff2aa9e931 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Fri, 8 Jun 2012 17:52:36 +0200 Subject: 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 --- test/files/neg/virtpatmat_unreach_select.check | 4 ++++ test/files/neg/virtpatmat_unreach_select.flags | 1 + test/files/neg/virtpatmat_unreach_select.scala | 12 ++++++++++++ 3 files changed, 17 insertions(+) create mode 100644 test/files/neg/virtpatmat_unreach_select.check create mode 100644 test/files/neg/virtpatmat_unreach_select.flags create mode 100644 test/files/neg/virtpatmat_unreach_select.scala (limited to 'test') 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 + } +} -- cgit v1.2.3