summaryrefslogtreecommitdiff
path: root/test
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 /test
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 'test')
-rw-r--r--test/files/neg/bug3683a.check6
-rw-r--r--test/files/neg/bug3683a.flags1
-rw-r--r--test/files/neg/bug3683a.scala20
-rw-r--r--test/files/neg/bug3683b.check6
-rw-r--r--test/files/neg/bug3683b.scala21
-rw-r--r--test/files/neg/exhausting.check9
-rw-r--r--test/files/neg/exhausting.scala7
7 files changed, 67 insertions, 3 deletions
diff --git a/test/files/neg/bug3683a.check b/test/files/neg/bug3683a.check
new file mode 100644
index 0000000000..a1c5b9c56d
--- /dev/null
+++ b/test/files/neg/bug3683a.check
@@ -0,0 +1,6 @@
+bug3683a.scala:14: error: match is not exhaustive!
+missing combination XX
+
+ w match {
+ ^
+one error found
diff --git a/test/files/neg/bug3683a.flags b/test/files/neg/bug3683a.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/neg/bug3683a.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/neg/bug3683a.scala b/test/files/neg/bug3683a.scala
new file mode 100644
index 0000000000..6d1915213a
--- /dev/null
+++ b/test/files/neg/bug3683a.scala
@@ -0,0 +1,20 @@
+sealed trait Foo
+sealed trait Bar extends Foo
+sealed trait W[T >: Bar <: Foo]
+case class X() extends W[Foo]
+case class XX() extends W[Bar]
+case class Y() extends W[Bar]
+case class Z[T >: Bar <: Foo](
+ z1: W[T]
+) extends W[T]
+
+object Main {
+ // should warn for not including XX()
+ def f1(w: W[Bar]): Int = {
+ w match {
+ // case XX() => 2
+ case Y() => 1
+ case Z(z) => f1(z)
+ }
+ }
+} \ No newline at end of file
diff --git a/test/files/neg/bug3683b.check b/test/files/neg/bug3683b.check
new file mode 100644
index 0000000000..3952633d1d
--- /dev/null
+++ b/test/files/neg/bug3683b.check
@@ -0,0 +1,6 @@
+bug3683b.scala:15: error: constructor cannot be instantiated to expected type;
+ found : X
+ required: W[Bar]
+ case X() => 1
+ ^
+one error found
diff --git a/test/files/neg/bug3683b.scala b/test/files/neg/bug3683b.scala
new file mode 100644
index 0000000000..646e418121
--- /dev/null
+++ b/test/files/neg/bug3683b.scala
@@ -0,0 +1,21 @@
+sealed trait Foo
+sealed trait Bar extends Foo
+sealed trait W[T >: Bar <: Foo]
+case class X() extends W[Foo]
+case class XX() extends W[Bar]
+case class Y() extends W[Bar]
+case class Z[T >: Bar <: Foo](
+ z1: W[T]
+) extends W[T]
+
+object Main {
+ // should fail for including X()
+ def f1(w: W[Bar]): Int = {
+ w match {
+ case X() => 1
+ case XX() => 2
+ case Y() => 1
+ case Z(z) => f1(z)
+ }
+ }
+} \ No newline at end of file
diff --git a/test/files/neg/exhausting.check b/test/files/neg/exhausting.check
index 6383a6eaca..d3f2251f79 100644
--- a/test/files/neg/exhausting.check
+++ b/test/files/neg/exhausting.check
@@ -14,11 +14,16 @@ missing combination Bar3
def fail3[T](x: Foo[T]) = x match {
^
exhausting.scala:31: error: match is not exhaustive!
+missing combination Bar2 Bar2
+
+ def fail4[T <: AnyRef](xx: (Foo[T], Foo[T])) = xx match {
+ ^
+exhausting.scala:36: error: match is not exhaustive!
missing combination Bar1 Bar2
missing combination Bar1 Bar3
missing combination Bar2 Bar1
missing combination Bar2 Bar2
- def fail4[T](xx: (Foo[T], Foo[T])) = xx match {
+ def fail5[T](xx: (Foo[T], Foo[T])) = xx match {
^
-four errors found
+5 errors found
diff --git a/test/files/neg/exhausting.scala b/test/files/neg/exhausting.scala
index 8b1ea817e4..0741d7467b 100644
--- a/test/files/neg/exhausting.scala
+++ b/test/files/neg/exhausting.scala
@@ -28,7 +28,12 @@ object Test {
case Bar1 => "ok"
case Bar2 => "ok"
}
- def fail4[T](xx: (Foo[T], Foo[T])) = xx match {
+ def fail4[T <: AnyRef](xx: (Foo[T], Foo[T])) = xx match {
+ case (Bar1, Bar1) => ()
+ case (Bar2, Bar3) => ()
+ case (Bar3, _) => ()
+ }
+ def fail5[T](xx: (Foo[T], Foo[T])) = xx match {
case (Bar1, Bar1) => ()
case (Bar2, Bar3) => ()
case (Bar3, _) => ()