summaryrefslogtreecommitdiff
path: root/test/files/neg
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-09-28 06:55:49 -0700
committerPaul Phillips <paulp@improving.org>2012-09-28 07:19:01 -0700
commit886c4061222773d76f3ee3f4ff1469f9d4a48eaf (patch)
tree70b13842e325bafd48e5494c844078f35b02f5b7 /test/files/neg
parent41f37bc428a309b9766f545da0179f270ea01d77 (diff)
parent57db28c55c3610f508b07940f7077cb73932418f (diff)
downloadscala-886c4061222773d76f3ee3f4ff1469f9d4a48eaf.tar.gz
scala-886c4061222773d76f3ee3f4ff1469f9d4a48eaf.tar.bz2
scala-886c4061222773d76f3ee3f4ff1469f9d4a48eaf.zip
Merge branch '2.10.x' into 210-merge
* 2.10.x: (37 commits) Added logic and tests for unchecked refinements. Moved isNonRefinementClassType somewhere logical. Moved two tests to less breaky locations. Nailed down the "impossible match" logic. Finish docs for string interpolation. moves Context.ParseError outside the cake revives macros.Infrastructure moves Context.runtimeUniverse to TreeBuild.mkRuntimeUniverseRef a more precise type for Context.mirror gets rid of macros.Infrastructure simplifies Context.Run and Context.CompilationUnit exposes Position.source as SourceFile removes extraneous stuff from macros.Infrastructure merges macros.CapturedVariables into macros.Universe merges macros.Exprs and macros.TypeTags into Context removes front ends from scala-reflect.jar PositionApi => Position hides BuildUtils from Scaladoc MirrorOf => Mirror docs.pre-lib now checks for mods in reflect ... Conflicts: test/files/neg/t4302.check test/files/neg/unchecked.check test/files/neg/unchecked2.check
Diffstat (limited to 'test/files/neg')
-rw-r--r--test/files/neg/patmat-type-check.check10
-rw-r--r--test/files/neg/t1872.check4
-rw-r--r--test/files/neg/t4302.check2
-rw-r--r--test/files/neg/t5762.check15
-rw-r--r--test/files/neg/t5762.flags1
-rw-r--r--test/files/neg/t5762.scala24
-rw-r--r--test/files/neg/unchecked-abstract.check27
-rw-r--r--test/files/neg/unchecked-abstract.flags1
-rw-r--r--test/files/neg/unchecked-abstract.scala93
-rw-r--r--test/files/neg/unchecked-impossible.check6
-rw-r--r--test/files/neg/unchecked-impossible.flags1
-rw-r--r--test/files/neg/unchecked-impossible.scala16
-rw-r--r--test/files/neg/unchecked-knowable.check6
-rw-r--r--test/files/neg/unchecked-knowable.flags1
-rw-r--r--test/files/neg/unchecked-knowable.scala20
-rw-r--r--test/files/neg/unchecked-refinement.check15
-rw-r--r--test/files/neg/unchecked-refinement.flags1
-rw-r--r--test/files/neg/unchecked-refinement.scala27
-rw-r--r--test/files/neg/unchecked.check2
-rw-r--r--test/files/neg/unchecked.scala4
-rw-r--r--test/files/neg/unchecked2.check62
-rw-r--r--test/files/neg/unchecked2.scala37
-rw-r--r--test/files/neg/unchecked3.check42
-rw-r--r--test/files/neg/unchecked3.flags1
-rw-r--r--test/files/neg/unchecked3.scala83
25 files changed, 472 insertions, 29 deletions
diff --git a/test/files/neg/patmat-type-check.check b/test/files/neg/patmat-type-check.check
index e045841ce1..721217c314 100644
--- a/test/files/neg/patmat-type-check.check
+++ b/test/files/neg/patmat-type-check.check
@@ -1,3 +1,12 @@
+patmat-type-check.scala:11: warning: fruitless type test: a value of type Test.Bop4[T] cannot also be a Seq[A]
+ def s3[T](x: Bop4[T]) = x match { case Seq('b', 'o', 'b') => true }
+ ^
+patmat-type-check.scala:15: warning: fruitless type test: a value of type Test.Bop5[_$1,T1,T2] cannot also be a Seq[A]
+ def s4[T1, T2](x: Bop5[_, T1, T2]) = x match { case Seq('b', 'o', 'b') => true }
+ ^
+patmat-type-check.scala:19: warning: fruitless type test: a value of type Test.Bop3[T] cannot also be a Seq[A]
+ def f4[T](x: Bop3[T]) = x match { case Seq('b', 'o', 'b') => true }
+ ^
patmat-type-check.scala:22: error: scrutinee is incompatible with pattern type;
found : Seq[A]
required: String
@@ -18,4 +27,5 @@ patmat-type-check.scala:30: error: scrutinee is incompatible with pattern type;
required: Test.Bop3[Char]
def f4[T](x: Bop3[Char]) = x match { case Seq('b', 'o', 'b') => true } // fail
^
+three warnings found
four errors found
diff --git a/test/files/neg/t1872.check b/test/files/neg/t1872.check
index ef84ef79e0..c5dc2a8080 100644
--- a/test/files/neg/t1872.check
+++ b/test/files/neg/t1872.check
@@ -1,4 +1,8 @@
+t1872.scala:3: warning: fruitless type test: a value of type Int cannot also be a scala.util.Random
+ def f(x: Int) = x.isInstanceOf[util.Random]
+ ^
t1872.scala:3: error: isInstanceOf cannot test if value types are references.
def f(x: Int) = x.isInstanceOf[util.Random]
^
+one warning found
one error found
diff --git a/test/files/neg/t4302.check b/test/files/neg/t4302.check
index 1a59b79a3b..ea48729276 100644
--- a/test/files/neg/t4302.check
+++ b/test/files/neg/t4302.check
@@ -1,4 +1,4 @@
-t4302.scala:2: warning: abstract type T in type T is unchecked since it is eliminated by erasure
+t4302.scala:2: warning: abstract type T is unchecked since it is eliminated by erasure
def hasMatch[T](x: AnyRef) = x.isInstanceOf[T]
^
error: No warnings can be incurred under -Xfatal-warnings.
diff --git a/test/files/neg/t5762.check b/test/files/neg/t5762.check
new file mode 100644
index 0000000000..2a2f12144a
--- /dev/null
+++ b/test/files/neg/t5762.check
@@ -0,0 +1,15 @@
+t5762.scala:6: warning: non-variable type argument Int in type pattern D[Int] is unchecked since it is eliminated by erasure
+ case _: D[Int] if bippy => 1
+ ^
+t5762.scala:7: warning: non-variable type argument String in type pattern D[String] is unchecked since it is eliminated by erasure
+ case _: D[String] => 2
+ ^
+t5762.scala:20: warning: non-variable type argument D[Int] in type pattern D[D[Int]] is unchecked since it is eliminated by erasure
+ case _: D[D[Int]] if bippy => 1
+ ^
+t5762.scala:21: warning: non-variable type argument D[String] in type pattern D[D[String]] is unchecked since it is eliminated by erasure
+ case _: D[D[String]] => 2
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+four warnings found
+one error found
diff --git a/test/files/neg/t5762.flags b/test/files/neg/t5762.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/neg/t5762.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/neg/t5762.scala b/test/files/neg/t5762.scala
new file mode 100644
index 0000000000..fb73552b12
--- /dev/null
+++ b/test/files/neg/t5762.scala
@@ -0,0 +1,24 @@
+class D[-A]
+
+object Test {
+ var bippy: Boolean = true
+ def f1(x: D[Int with String]) = x match {
+ case _: D[Int] if bippy => 1
+ case _: D[String] => 2
+ }
+ // Correctly warns:
+ //
+ // a.scala:5: warning: non variable type-argument Int in type pattern D[Int] is unchecked since it is eliminated by erasure
+ // case _: D[Int] => 1
+ // ^
+ // a.scala:6: warning: non variable type-argument String in type pattern D[String] is unchecked since it is eliminated by erasure
+ // case _: D[String] => 2
+ // ^
+ // two warnings found
+
+ def f2(x: D[D[Int] with D[String]]) = x match {
+ case _: D[D[Int]] if bippy => 1
+ case _: D[D[String]] => 2
+ }
+ // No warnings!
+}
diff --git a/test/files/neg/unchecked-abstract.check b/test/files/neg/unchecked-abstract.check
new file mode 100644
index 0000000000..762859574b
--- /dev/null
+++ b/test/files/neg/unchecked-abstract.check
@@ -0,0 +1,27 @@
+unchecked-abstract.scala:16: warning: abstract type H in type Con[M.this.H] is unchecked since it is eliminated by erasure
+ /* warn */ println(x.isInstanceOf[Con[H]])
+ ^
+unchecked-abstract.scala:21: warning: abstract type H in type Con[M.this.H] is unchecked since it is eliminated by erasure
+ /* warn */ println(x.isInstanceOf[Con[H]])
+ ^
+unchecked-abstract.scala:27: warning: abstract type T in type Inv[M.this.T] is unchecked since it is eliminated by erasure
+ /* warn */ println(x.isInstanceOf[Inv[T]])
+ ^
+unchecked-abstract.scala:28: warning: abstract type L in type Inv[M.this.L] is unchecked since it is eliminated by erasure
+ /* warn */ println(x.isInstanceOf[Inv[L]])
+ ^
+unchecked-abstract.scala:31: warning: abstract type H in type Inv[M.this.H] is unchecked since it is eliminated by erasure
+ /* warn */ println(x.isInstanceOf[Inv[H]])
+ ^
+unchecked-abstract.scala:33: warning: abstract type L in type Inv[M.this.L] is unchecked since it is eliminated by erasure
+ /* warn */ println(x.isInstanceOf[Inv[L]])
+ ^
+unchecked-abstract.scala:36: warning: abstract type H in type Inv[M.this.H] is unchecked since it is eliminated by erasure
+ /* warn */ println(x.isInstanceOf[Inv[H]])
+ ^
+unchecked-abstract.scala:37: warning: abstract type T in type Inv[M.this.T] is unchecked since it is eliminated by erasure
+ /* warn */ println(x.isInstanceOf[Inv[T]])
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+8 warnings found
+one error found
diff --git a/test/files/neg/unchecked-abstract.flags b/test/files/neg/unchecked-abstract.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/neg/unchecked-abstract.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/neg/unchecked-abstract.scala b/test/files/neg/unchecked-abstract.scala
new file mode 100644
index 0000000000..5b915755f4
--- /dev/null
+++ b/test/files/neg/unchecked-abstract.scala
@@ -0,0 +1,93 @@
+trait Con[-X]
+trait Inv[X]
+trait Cov[+X]
+
+abstract class M {
+ type H
+ type L <: H
+ type T >: L <: H
+
+ def h1(x: Con[H]) = {
+ /* nowarn */ println(x.isInstanceOf[Con[H]])
+ /* nowarn */ println(x.isInstanceOf[Con[T]])
+ /* nowarn */ println(x.isInstanceOf[Con[L]])
+ }
+ def h2(x: Con[T]) = {
+ /* warn */ println(x.isInstanceOf[Con[H]])
+ /* nowarn */ println(x.isInstanceOf[Con[T]])
+ /* nowarn */ println(x.isInstanceOf[Con[L]])
+ }
+ def h3(x: Con[L]) = {
+ /* warn */ println(x.isInstanceOf[Con[H]])
+ /* warn */ println(x.isInstanceOf[Con[T]])
+ /* nowarn */ println(x.isInstanceOf[Con[L]])
+ }
+ def h4(x: Inv[H]) = {
+ /* nowarn */ println(x.isInstanceOf[Inv[H]])
+ /* warn */ println(x.isInstanceOf[Inv[T]])
+ /* warn */ println(x.isInstanceOf[Inv[L]])
+ }
+ def h5(x: Inv[T]) = {
+ /* warn */ println(x.isInstanceOf[Inv[H]])
+ /* nowarn */ println(x.isInstanceOf[Inv[T]])
+ /* warn */ println(x.isInstanceOf[Inv[L]])
+ }
+ def h6(x: Inv[L]) = {
+ /* warn */ println(x.isInstanceOf[Inv[H]])
+ /* warn */ println(x.isInstanceOf[Inv[T]])
+ /* nowarn */ println(x.isInstanceOf[Inv[L]])
+ }
+ def h7(x: Cov[H]) = {
+ /* nowarn */ println(x.isInstanceOf[Cov[H]])
+ /* warn */ println(x.isInstanceOf[Cov[T]])
+ /* warn */ println(x.isInstanceOf[Cov[L]])
+ }
+ def h8(x: Cov[T]) = {
+ /* nowarn */ println(x.isInstanceOf[Cov[H]])
+ /* nowarn */ println(x.isInstanceOf[Cov[T]])
+ /* warn */ println(x.isInstanceOf[Cov[L]])
+ }
+ def h9(x: Cov[L]) = {
+ /* nowarn */ println(x.isInstanceOf[Cov[H]])
+ /* nowarn */ println(x.isInstanceOf[Cov[T]])
+ /* nowarn */ println(x.isInstanceOf[Cov[L]])
+ }
+}
+
+object Test extends M {
+ type H = Any
+ type T = Int
+ type L = Nothing
+
+ val conh = new Con[H] { }
+ val cont = new Con[T] { }
+ val conl = new Con[L] { }
+
+ val invh = new Inv[H] { }
+ val invt = new Inv[T] { }
+ val invl = new Inv[L] { }
+
+ val covh = new Cov[H] { }
+ val covt = new Cov[T] { }
+ val covl = new Cov[L] { }
+
+ def main(args: Array[String]): Unit = {
+ h1(conh)
+ h2(conh)
+ h2(cont)
+ h3(conh)
+ h3(cont)
+ h3(conl)
+
+ h4(invh)
+ h5(invt)
+ h6(invl)
+
+ h7(covh)
+ h7(covt)
+ h7(covl)
+ h8(covt)
+ h8(covl)
+ h9(covl)
+ }
+}
diff --git a/test/files/neg/unchecked-impossible.check b/test/files/neg/unchecked-impossible.check
new file mode 100644
index 0000000000..75fc390fa8
--- /dev/null
+++ b/test/files/neg/unchecked-impossible.check
@@ -0,0 +1,6 @@
+unchecked-impossible.scala:5: warning: fruitless type test: a value of type T2[Int,Int] cannot also be a Seq[A]
+ case Seq(x) =>
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
+one error found
diff --git a/test/files/neg/unchecked-impossible.flags b/test/files/neg/unchecked-impossible.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/neg/unchecked-impossible.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/neg/unchecked-impossible.scala b/test/files/neg/unchecked-impossible.scala
new file mode 100644
index 0000000000..985a2d0b08
--- /dev/null
+++ b/test/files/neg/unchecked-impossible.scala
@@ -0,0 +1,16 @@
+final case class T2[+A, +B](a: A, b: B)
+
+class A {
+ def f1 = T2(1, 2) match {
+ case Seq(x) =>
+ case _ =>
+ }
+ def f2 = T2(1, 2) match {
+ case _: T2[Int, Int] => /* nowarn */
+ case _ =>
+ }
+ def f3 = T2(1, 2) match {
+ case _: T2[_, Int] => /* nowarn */
+ case _ =>
+ }
+}
diff --git a/test/files/neg/unchecked-knowable.check b/test/files/neg/unchecked-knowable.check
new file mode 100644
index 0000000000..28e2d67920
--- /dev/null
+++ b/test/files/neg/unchecked-knowable.check
@@ -0,0 +1,6 @@
+unchecked-knowable.scala:17: warning: fruitless type test: a value of type Bippy cannot also be a A1
+ /* warn */ (new Bippy).isInstanceOf[A1]
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
+one error found
diff --git a/test/files/neg/unchecked-knowable.flags b/test/files/neg/unchecked-knowable.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/neg/unchecked-knowable.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/neg/unchecked-knowable.scala b/test/files/neg/unchecked-knowable.scala
new file mode 100644
index 0000000000..667b47f504
--- /dev/null
+++ b/test/files/neg/unchecked-knowable.scala
@@ -0,0 +1,20 @@
+/** Knowable - only final leaves */
+sealed abstract class A1
+sealed abstract class A2 extends A1
+final class A3 extends A1
+final class A4 extends A2
+
+/** Unknowable */
+sealed abstract class B1
+sealed abstract class B2 extends B1
+final class B3 extends B1
+trait B4 extends B2
+
+class Bippy
+trait Dingus
+
+class A {
+ /* warn */ (new Bippy).isInstanceOf[A1]
+ /* nowarn */ (new Bippy).isInstanceOf[B1]
+ /* nowarn */ ((new Bippy): Any).isInstanceOf[A1]
+}
diff --git a/test/files/neg/unchecked-refinement.check b/test/files/neg/unchecked-refinement.check
new file mode 100644
index 0000000000..e85a51f44d
--- /dev/null
+++ b/test/files/neg/unchecked-refinement.check
@@ -0,0 +1,15 @@
+unchecked-refinement.scala:17: warning: abstract type U in type pattern Foo[U,U,V] is unchecked since it is eliminated by erasure
+ /* warn */ case _: Foo[U, U, V] if b => ()
+ ^
+unchecked-refinement.scala:19: warning: non-variable type argument Any in type pattern Foo[Any,U,V] is unchecked since it is eliminated by erasure
+ /* warn */ case _: Foo[Any, U, V] if b => ()
+ ^
+unchecked-refinement.scala:23: warning: a pattern match on a refinement type is unchecked
+ /* nowarn - todo */ case x: AnyRef { def bippy: Int } if b => x.bippy // this could/should do an instance check and not warn
+ ^
+unchecked-refinement.scala:24: warning: a pattern match on a refinement type is unchecked
+ /* nowarn - todo */ case x: AnyRef { def size: Int } if b => x.size // this could/should do a static conformance test and not warn
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+four warnings found
+one error found
diff --git a/test/files/neg/unchecked-refinement.flags b/test/files/neg/unchecked-refinement.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/neg/unchecked-refinement.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/neg/unchecked-refinement.scala b/test/files/neg/unchecked-refinement.scala
new file mode 100644
index 0000000000..79ed7f13c1
--- /dev/null
+++ b/test/files/neg/unchecked-refinement.scala
@@ -0,0 +1,27 @@
+// a.scala
+// Thu Sep 27 09:42:16 PDT 2012
+
+trait Bar[-T1, T2, +T3] { }
+trait Foo[-T1, T2, +T3] extends Bar[T1, T2, T3]
+
+class A {
+ var b = true
+
+ def f1(x: Foo[Int, Int, Int]) = x match {
+ /* nowarn */ case _: Foo[Nothing, Int, Any] => true
+ }
+ def f2[T, U, V](x: Foo[T, U, V]) = x match {
+ /* nowarn */ case _: Foo[Nothing, U, Any] => true
+ }
+ def f3[T, U, V](x: Foo[T, U, V]) = x match {
+ /* warn */ case _: Foo[U, U, V] if b => ()
+ /* nowarn */ case _: Foo[Nothing, U, V] if b => ()
+ /* warn */ case _: Foo[Any, U, V] if b => ()
+ }
+
+ def f4(xs: List[Int]) = xs match {
+ /* nowarn - todo */ case x: AnyRef { def bippy: Int } if b => x.bippy // this could/should do an instance check and not warn
+ /* nowarn - todo */ case x: AnyRef { def size: Int } if b => x.size // this could/should do a static conformance test and not warn
+ /* nowarn */ case x: ((AnyRef { def size: Int }) @unchecked) if b => x.size
+ }
+}
diff --git a/test/files/neg/unchecked.check b/test/files/neg/unchecked.check
index 19b8c908da..570f02f219 100644
--- a/test/files/neg/unchecked.check
+++ b/test/files/neg/unchecked.check
@@ -2,7 +2,7 @@ unchecked.scala:18: warning: non-variable type argument String in type pattern I
case xs: Iterable[String] => xs.head // unchecked
^
unchecked.scala:22: warning: non-variable type argument Any in type pattern Set[Any] is unchecked since it is eliminated by erasure
- case xs: Set[Any] => xs.head // unchecked
+ case xs: Set[Any] => xs.head // unchecked
^
unchecked.scala:26: warning: non-variable type argument Any in type pattern Map[Any,Any] is unchecked since it is eliminated by erasure
case xs: Map[Any, Any] => xs.head // unchecked
diff --git a/test/files/neg/unchecked.scala b/test/files/neg/unchecked.scala
index b50cdf9d7a..e491b253ba 100644
--- a/test/files/neg/unchecked.scala
+++ b/test/files/neg/unchecked.scala
@@ -19,8 +19,8 @@ object Test {
case _ => 0
}
def f3(x: Any) = x match {
- case xs: Set[Any] => xs.head // unchecked
- case _ => 0
+ case xs: Set[Any] => xs.head // unchecked
+ case _ => 0
}
def f4(x: Any) = x match {
case xs: Map[Any, Any] => xs.head // unchecked
diff --git a/test/files/neg/unchecked2.check b/test/files/neg/unchecked2.check
index 599d11c43a..a7b8391856 100644
--- a/test/files/neg/unchecked2.check
+++ b/test/files/neg/unchecked2.check
@@ -1,21 +1,45 @@
-unchecked2.scala:2: warning: non-variable type argument Int in type Option[Int] is unchecked since it is eliminated by erasure
- Some(123).isInstanceOf[Option[Int]]
- ^
-unchecked2.scala:3: warning: non-variable type argument String in type Option[String] is unchecked since it is eliminated by erasure
- Some(123).isInstanceOf[Option[String]]
- ^
-unchecked2.scala:4: warning: non-variable type argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure
- Some(123).isInstanceOf[Option[List[String]]]
- ^
-unchecked2.scala:5: warning: non-variable type argument List[Int => String] in type Option[List[Int => String]] is unchecked since it is eliminated by erasure
- Some(123).isInstanceOf[Option[List[Int => String]]]
- ^
-unchecked2.scala:6: warning: non-variable type argument (String, Double) in type Option[(String, Double)] is unchecked since it is eliminated by erasure
- Some(123).isInstanceOf[Option[(String, Double)]]
- ^
-unchecked2.scala:7: warning: non-variable type argument String => Double in type Option[String => Double] is unchecked since it is eliminated by erasure
- Some(123).isInstanceOf[Option[String => Double]]
- ^
+unchecked2.scala:4: warning: fruitless type test: a value of type Some[List[Int]] cannot also be a Option[List[String]] (but still might match its erasure)
+ /* warn */ Some(List(1)).isInstanceOf[Option[List[String]]]
+ ^
+unchecked2.scala:5: warning: non-variable type argument Option[_] in type Option[Option[_]] is unchecked since it is eliminated by erasure
+ /* warn */ Some(123).isInstanceOf[Option[Option[_]]]
+ ^
+unchecked2.scala:6: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[String] (but still might match its erasure)
+ /* warn */ Some(123).isInstanceOf[Option[String]]
+ ^
+unchecked2.scala:7: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[List[String]] (but still might match its erasure)
+ /* warn */ Some(123).isInstanceOf[Option[List[String]]]
+ ^
+unchecked2.scala:8: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[List[Int => String]] (but still might match its erasure)
+ /* warn */ Some(123).isInstanceOf[Option[List[Int => String]]]
+ ^
+unchecked2.scala:9: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[(String, Double)] (but still might match its erasure)
+ /* warn */ Some(123).isInstanceOf[Option[(String, Double)]]
+ ^
+unchecked2.scala:10: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[String => Double] (but still might match its erasure)
+ /* warn */ Some(123).isInstanceOf[Option[String => Double]]
+ ^
+unchecked2.scala:14: warning: non-variable type argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure
+ /* warn */ (Some(List(1)): Any).isInstanceOf[Option[List[String]]]
+ ^
+unchecked2.scala:15: warning: non-variable type argument Int in type Option[Int] is unchecked since it is eliminated by erasure
+ /* warn */ (Some(123): Any).isInstanceOf[Option[Int]]
+ ^
+unchecked2.scala:16: warning: non-variable type argument String in type Option[String] is unchecked since it is eliminated by erasure
+ /* warn */ (Some(123): Any).isInstanceOf[Option[String]]
+ ^
+unchecked2.scala:17: warning: non-variable type argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure
+ /* warn */ (Some(123): Any).isInstanceOf[Option[List[String]]]
+ ^
+unchecked2.scala:18: warning: non-variable type argument List[Int => String] in type Option[List[Int => String]] is unchecked since it is eliminated by erasure
+ /* warn */ (Some(123): Any).isInstanceOf[Option[List[Int => String]]]
+ ^
+unchecked2.scala:19: warning: non-variable type argument (String, Double) in type Option[(String, Double)] is unchecked since it is eliminated by erasure
+ /* warn */ (Some(123): Any).isInstanceOf[Option[(String, Double)]]
+ ^
+unchecked2.scala:20: warning: non-variable type argument String => Double in type Option[String => Double] is unchecked since it is eliminated by erasure
+ /* warn */ (Some(123): Any).isInstanceOf[Option[String => Double]]
+ ^
error: No warnings can be incurred under -Xfatal-warnings.
-6 warnings found
+14 warnings found
one error found
diff --git a/test/files/neg/unchecked2.scala b/test/files/neg/unchecked2.scala
index a2e757e1dc..616b05aad8 100644
--- a/test/files/neg/unchecked2.scala
+++ b/test/files/neg/unchecked2.scala
@@ -1,8 +1,33 @@
object Test {
- Some(123).isInstanceOf[Option[Int]]
- Some(123).isInstanceOf[Option[String]]
- Some(123).isInstanceOf[Option[List[String]]]
- Some(123).isInstanceOf[Option[List[Int => String]]]
- Some(123).isInstanceOf[Option[(String, Double)]]
- Some(123).isInstanceOf[Option[String => Double]]
+ // These warn because it can be statically shown they won't match.
+
+ /* warn */ Some(List(1)).isInstanceOf[Option[List[String]]]
+ /* warn */ Some(123).isInstanceOf[Option[Option[_]]]
+ /* warn */ Some(123).isInstanceOf[Option[String]]
+ /* warn */ Some(123).isInstanceOf[Option[List[String]]]
+ /* warn */ Some(123).isInstanceOf[Option[List[Int => String]]]
+ /* warn */ Some(123).isInstanceOf[Option[(String, Double)]]
+ /* warn */ Some(123).isInstanceOf[Option[String => Double]]
+
+ // These warn because you can't check at runtime.
+
+ /* warn */ (Some(List(1)): Any).isInstanceOf[Option[List[String]]]
+ /* warn */ (Some(123): Any).isInstanceOf[Option[Int]]
+ /* warn */ (Some(123): Any).isInstanceOf[Option[String]]
+ /* warn */ (Some(123): Any).isInstanceOf[Option[List[String]]]
+ /* warn */ (Some(123): Any).isInstanceOf[Option[List[Int => String]]]
+ /* warn */ (Some(123): Any).isInstanceOf[Option[(String, Double)]]
+ /* warn */ (Some(123): Any).isInstanceOf[Option[String => Double]]
+
+ // These don't warn.
+
+ /* nowarn */ Some(List(1)).isInstanceOf[Option[List[Int]]]
+ /* nowarn */ Some(123).isInstanceOf[Option[Int]]
+ /* nowarn */ Some(123).isInstanceOf[Some[Int]]
+ /* nowarn */ Some(123).isInstanceOf[AnyRef]
+
+ /* nowarn */ (Some(List(1)): Any).isInstanceOf[Option[_]]
+ /* nowarn */ (Some(123): Any).isInstanceOf[Option[_]]
+ /* nowarn */ (Some(123): Any).isInstanceOf[Some[_]]
+ /* nowarn */ (Some(123): Any).isInstanceOf[AnyRef]
}
diff --git a/test/files/neg/unchecked3.check b/test/files/neg/unchecked3.check
new file mode 100644
index 0000000000..a7582a8930
--- /dev/null
+++ b/test/files/neg/unchecked3.check
@@ -0,0 +1,42 @@
+unchecked3.scala:24: warning: non-variable type argument Double in type pattern E1[Double] is unchecked since it is eliminated by erasure
+ /* warn */ def peerTypes2(x: B1[Int]) = x match { case _: E1[Double] => true }
+ ^
+unchecked3.scala:25: warning: non-variable type argument Double in type pattern F1[Double] is unchecked since it is eliminated by erasure
+ /* warn */ def peerTypes3(x: B1[_]) = x match { case _: F1[Double] => true }
+ ^
+unchecked3.scala:28: warning: non-variable type argument Int in type pattern A2[Int] is unchecked since it is eliminated by erasure
+ /* warn */ def twotypes1[T](x: B2[T, Int]) = x match { case _: A2[Int] => true }
+ ^
+unchecked3.scala:32: warning: non-variable type argument Int in type pattern B2[_,Int] is unchecked since it is eliminated by erasure
+ /* warn */ def twotypes5[T](x: A2[T]) = x match { case _: B2[_, Int] => true }
+ ^
+unchecked3.scala:40: warning: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure
+ /* warn */ case _: Array[List[String]] => ()
+ ^
+unchecked3.scala:43: warning: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure
+ /* warn */ case _: Array[Array[List[String]]] => ()
+ ^
+unchecked3.scala:50: warning: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure
+ /* warn */ case _: Array[List[String]] => ()
+ ^
+unchecked3.scala:53: warning: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure
+ /* warn */ case _: Array[Array[List[String]]] => ()
+ ^
+unchecked3.scala:60: warning: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure
+ /* warn */ case _: Array[List[String]] => ()
+ ^
+unchecked3.scala:62: warning: non-variable type argument Array[String] in type pattern Array[List[Array[String]]] is unchecked since it is eliminated by erasure
+ /* warn */ case _: Array[List[Array[String]]] => ()
+ ^
+unchecked3.scala:63: warning: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure
+ /* warn */ case _: Array[Array[List[String]]] => ()
+ ^
+unchecked3.scala:75: warning: abstract type A in type pattern Set[Q.this.A] is unchecked since it is eliminated by erasure
+ /* warn */ case xs: Set[A] => xs.head
+ ^
+unchecked3.scala:62: warning: unreachable code
+ /* warn */ case _: Array[List[Array[String]]] => ()
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+13 warnings found
+one error found
diff --git a/test/files/neg/unchecked3.flags b/test/files/neg/unchecked3.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/neg/unchecked3.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/neg/unchecked3.scala b/test/files/neg/unchecked3.scala
new file mode 100644
index 0000000000..7b8c13e8f8
--- /dev/null
+++ b/test/files/neg/unchecked3.scala
@@ -0,0 +1,83 @@
+sealed trait A2[T1]
+final class B2[T1, T2] extends A2[T1]
+
+sealed trait A[T]
+final class B[T] extends A[T]
+
+sealed trait A1[T]
+trait B1[T] extends A1[T]
+trait C1[T] extends A1[T]
+trait D1[T] extends A1[Int]
+trait E1[T] extends B1[Int]
+trait F1[T] extends B1[T]
+
+object MiscUnchecked {
+ /* nowarn */ def knownType1(x: A[Int]) = x match { case _: B[Int] if true => 1 }
+ /* nowarn */ def knownType2(x: B[Int]) = x match { case _: A[Int] if true => 1 }
+ /* nowarn */ def tparamLeakage1(x: Any) = x match { case Array() => 1 }
+ /* nowarn */ def tparamLeakage2(x: Any) = x match { case List() => 1 }
+
+ // E1[Double] implies B1[Int], but B1[Int] does not imply E1[Double], even if .isInstanceOf[E1[_]]
+ // F1[Int] implies B1[Int], and B1[Int] implies F1[Int]
+
+ /* nowarn */ def peerTypes1(x: B1[Int]) = x match { case _: C1[Int] => true }
+ /* warn */ def peerTypes2(x: B1[Int]) = x match { case _: E1[Double] => true }
+ /* warn */ def peerTypes3(x: B1[_]) = x match { case _: F1[Double] => true }
+ /* nowarn */ def peerTypes4(x: B1[Int]) = x match { case _: F1[Int] => true }
+
+ /* warn */ def twotypes1[T](x: B2[T, Int]) = x match { case _: A2[Int] => true }
+ /* nowarn */ def twotypes2[T](x: B2[Int, T]) = x match { case _: A2[Int] => true }
+ /* nowarn */ def twotypes3(x: A2[Int]) = x match { case _: B2[Int, _] => true }
+ /* nowarn */ def twotypes4[T](x: A2[T]) = x match { case _: B2[T, _] => true }
+ /* warn */ def twotypes5[T](x: A2[T]) = x match { case _: B2[_, Int] => true }
+}
+
+object Arrays {
+ def f1(x: Any) = x match {
+ /* nowarn */ case _: Array[Int] => ()
+ /* nowarn */ case _: Array[Boolean] => ()
+ /* nowarn */ case _: Array[String] => ()
+ /* warn */ case _: Array[List[String]] => ()
+ /* nowarn */ case _: Array[Array[String]] => ()
+ /* nowarn */ case _: Array[Array[Array[String]]] => ()
+ /* warn */ case _: Array[Array[List[String]]] => ()
+ }
+
+ def f2(x: Array[_]) = x match {
+ /* nowarn */ case _: Array[Int] => ()
+ /* nowarn */ case _: Array[Boolean] => ()
+ /* nowarn */ case _: Array[String] => ()
+ /* warn */ case _: Array[List[String]] => ()
+ /* nowarn */ case _: Array[Array[String]] => ()
+ /* nowarn */ case _: Array[Array[Array[String]]] => ()
+ /* warn */ case _: Array[Array[List[String]]] => ()
+ }
+
+ def f3[T](x: Array[T]) = x match {
+ /* nowarn */ case _: Array[Int] => ()
+ /* nowarn */ case _: Array[Boolean] => ()
+ /* nowarn */ case _: Array[String] => ()
+ /* warn */ case _: Array[List[String]] => ()
+ /* nowarn */ case _: Array[Array[String]] => ()
+ /* warn */ case _: Array[List[Array[String]]] => ()
+ /* warn */ case _: Array[Array[List[String]]] => ()
+ }
+}
+
+object Matching {
+ class Q {
+ type A
+ type B <: A
+
+ def f(xs: Traversable[B]) = xs match {
+ /* nowarn */ case xs: List[A] => xs.head
+ /* nowarn */ case xs: Seq[B] => xs.head
+ /* warn */ case xs: Set[A] => xs.head
+ }
+ def f2[T <: B](xs: Traversable[T]) = xs match {
+ /* nowarn */ case xs: List[B with T] => xs.head
+ /* nowarn */ case xs: Seq[A] => xs.head
+ /* nowarn */ case xs: Set[T] => xs.head
+ }
+ }
+}