diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-11-21 15:11:48 +0100 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-11-21 15:11:48 +0100 |
commit | 304edd816329703919808e5ec851ed946e6f549f (patch) | |
tree | 7e39c66afda33546ad91fa5500817a731129da5b /test | |
parent | 495fdb3d72194c8b5010e98a1186ccafc95fbd8a (diff) | |
parent | 9266dee17c563c3394077e747c5037050cafcde2 (diff) | |
download | scala-304edd816329703919808e5ec851ed946e6f549f.tar.gz scala-304edd816329703919808e5ec851ed946e6f549f.tar.bz2 scala-304edd816329703919808e5ec851ed946e6f549f.zip |
Merge pull request #4115 from retronym/ticket/8597
SI-8597 Improved pattern unchecked warnings
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/t8597.check | 21 | ||||
-rw-r--r-- | test/files/neg/t8597.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t8597.scala | 27 | ||||
-rw-r--r-- | test/files/neg/t8597b.check | 6 | ||||
-rw-r--r-- | test/files/neg/t8597b.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t8597b.scala | 21 | ||||
-rw-r--r-- | test/files/neg/unchecked-abstract.check | 14 |
7 files changed, 90 insertions, 1 deletions
diff --git a/test/files/neg/t8597.check b/test/files/neg/t8597.check new file mode 100644 index 0000000000..bc945f9191 --- /dev/null +++ b/test/files/neg/t8597.check @@ -0,0 +1,21 @@ +t8597.scala:2: warning: abstract type T in type pattern Some[T] is unchecked since it is eliminated by erasure + def nowarn[T] = (null: Any) match { case _: Some[T] => } // warn (did not warn due to SI-8597) + ^ +t8597.scala:5: warning: abstract type pattern T is unchecked since it is eliminated by erasure + def warn1[T] = (null: Any) match { case _: T => } // warn + ^ +t8597.scala:6: warning: non-variable type argument String in type pattern Some[String] is unchecked since it is eliminated by erasure + def warn2 = (null: Any) match { case _: Some[String] => } // warn + ^ +t8597.scala:7: warning: non-variable type argument Unchecked.this.C in type pattern Some[Unchecked.this.C] is unchecked since it is eliminated by erasure + (null: Any) match { case _: Some[C] => } // warn + ^ +t8597.scala:18: warning: abstract type T in type pattern Array[T] is unchecked since it is eliminated by erasure + def warnArray[T] = (null: Any) match { case _: Array[T] => } // warn (did not warn due to SI-8597) + ^ +t8597.scala:26: warning: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure + def warnArrayErasure2 = (null: Any) match {case Some(_: Array[Array[List[String]]]) => } // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +6 warnings found +one error found diff --git a/test/files/neg/t8597.flags b/test/files/neg/t8597.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/neg/t8597.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/neg/t8597.scala b/test/files/neg/t8597.scala new file mode 100644 index 0000000000..068e87d91a --- /dev/null +++ b/test/files/neg/t8597.scala @@ -0,0 +1,27 @@ +class Unchecked[C] { + def nowarn[T] = (null: Any) match { case _: Some[T] => } // warn (did not warn due to SI-8597) + + // These warned before. + def warn1[T] = (null: Any) match { case _: T => } // warn + def warn2 = (null: Any) match { case _: Some[String] => } // warn + (null: Any) match { case _: Some[C] => } // warn + + // These must remain without warnings. These are excerpts from + // related tests that are more exhauative. + class C; class D extends C + def okay = (List(new D) : Seq[D]) match { case _: List[C] => case _ => } // nowarn + class B2[A, B] + class A2[X] extends B2[X, String] + def okay2(x: A2[Int]) = x match { case _: B2[Int, _] => true } // nowarn + def okay3(x: A2[Int]) = x match { case _: B2[Int, typeVar] => true } // nowarn + + def warnArray[T] = (null: Any) match { case _: Array[T] => } // warn (did not warn due to SI-8597) + def nowarnArrayC = (null: Any) match { case _: Array[C] => } // nowarn + + def nowarnArrayTypeVar[T] = (null: Any) match { case _: Array[t] => } // nowarn + + def noWarnArrayErasure1 = (null: Any) match {case Some(_: Array[String]) => } // nowarn + def noWarnArrayErasure2 = (null: Any) match {case Some(_: Array[List[_]]) => } // nowarn + def noWarnArrayErasure3 = (null: Any) match {case Some(_: Array[Array[List[_]]]) => } // nowarn + def warnArrayErasure2 = (null: Any) match {case Some(_: Array[Array[List[String]]]) => } // warn +} diff --git a/test/files/neg/t8597b.check b/test/files/neg/t8597b.check new file mode 100644 index 0000000000..3c45a31337 --- /dev/null +++ b/test/files/neg/t8597b.check @@ -0,0 +1,6 @@ +t8597b.scala:18: warning: non-variable type argument T in type pattern Some[T] is unchecked since it is eliminated by erasure + case _: Some[T] => // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/test/files/neg/t8597b.flags b/test/files/neg/t8597b.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/neg/t8597b.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/neg/t8597b.scala b/test/files/neg/t8597b.scala new file mode 100644 index 0000000000..b29d591cb1 --- /dev/null +++ b/test/files/neg/t8597b.scala @@ -0,0 +1,21 @@ +object Unchecked { + (null: Any) match { + case _: Some[t] => + + // t is a fresh pattern type variable, despite our attempts to + // backtick our way to the enclosing `t`. Under this interpretation, + // the absense of an unchecked warning is expected. + (null: Any) match { + case _: Some[t] => // no warn + } + (null: Any) match { + case _: Some[`t`] => // no warn + } + + // here we correctly issue an unchecked warning + type T = t + (null: Any) match { + case _: Some[T] => // warn + } + } +} diff --git a/test/files/neg/unchecked-abstract.check b/test/files/neg/unchecked-abstract.check index 72019082ac..703929dca8 100644 --- a/test/files/neg/unchecked-abstract.check +++ b/test/files/neg/unchecked-abstract.check @@ -4,6 +4,9 @@ unchecked-abstract.scala:16: warning: abstract type H in type Contravariant[M.th unchecked-abstract.scala:21: warning: abstract type H in type Contravariant[M.this.H] is unchecked since it is eliminated by erasure /* warn */ println(x.isInstanceOf[Contravariant[H]]) ^ +unchecked-abstract.scala:22: warning: abstract type T in type Contravariant[M.this.T] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Contravariant[T]]) + ^ unchecked-abstract.scala:27: warning: abstract type T in type Invariant[M.this.T] is unchecked since it is eliminated by erasure /* warn */ println(x.isInstanceOf[Invariant[T]]) ^ @@ -22,6 +25,15 @@ unchecked-abstract.scala:36: warning: abstract type H in type Invariant[M.this.H unchecked-abstract.scala:37: warning: abstract type T in type Invariant[M.this.T] is unchecked since it is eliminated by erasure /* warn */ println(x.isInstanceOf[Invariant[T]]) ^ +unchecked-abstract.scala:42: warning: abstract type T in type Covariant[M.this.T] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Covariant[T]]) + ^ +unchecked-abstract.scala:43: warning: abstract type L in type Covariant[M.this.L] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Covariant[L]]) + ^ +unchecked-abstract.scala:48: warning: abstract type L in type Covariant[M.this.L] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Covariant[L]]) + ^ error: No warnings can be incurred under -Xfatal-warnings. -8 warnings found +12 warnings found one error found |