summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-11-26 23:11:29 -0800
committerJason Zaugg <jzaugg@gmail.com>2013-11-26 23:11:29 -0800
commitcb5833414c85a0fff815d5d1cb1d99540341046b (patch)
treece1748ebff2d90db1fdccd60b8b6bab58f1b55e0
parent7cd50ba39c332c39990bc3a7103e1f86b040032e (diff)
parent0271a4a3944153bb4fcc81e3b250bc084b692db3 (diff)
downloadscala-cb5833414c85a0fff815d5d1cb1d99540341046b.tar.gz
scala-cb5833414c85a0fff815d5d1cb1d99540341046b.tar.bz2
scala-cb5833414c85a0fff815d5d1cb1d99540341046b.zip
Merge pull request #3161 from retronym/ticket/7984
Issue unchecked warning for type aliases
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Checkable.scala12
-rw-r--r--test/files/neg/t3692-new.check6
-rw-r--r--test/files/neg/t7984.check6
-rw-r--r--test/files/neg/t7984.flags1
-rw-r--r--test/files/neg/t7984.scala7
-rw-r--r--test/files/neg/unchecked-suppress.check4
-rw-r--r--test/files/neg/unchecked.check6
-rw-r--r--test/files/neg/unchecked3.check2
8 files changed, 30 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Checkable.scala b/src/compiler/scala/tools/nsc/typechecker/Checkable.scala
index 0eae17612d..94f8f509fc 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Checkable.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Checkable.scala
@@ -259,10 +259,12 @@ trait Checkable {
if (uncheckedOk(P0)) return
def where = if (inPattern) "pattern " else ""
- // singleton types not considered here
- val P = P0.widen
+ // singleton types not considered here, dealias the pattern for SI-XXXX
+ val P = P0.dealiasWiden
val X = X0.widen
+ def PString = if (P eq P0) P.toString else s"$P (the underlying of $P0)"
+
P match {
// Prohibit top-level type tests for these, but they are ok nested (e.g. case Foldable[Nothing] => ... )
case TypeRef(_, NothingClass | NullClass | AnyValClass, _) =>
@@ -282,12 +284,12 @@ trait Checkable {
if (checker.neverMatches) {
val addendum = if (checker.neverSubClass) "" else " (but still might match its erasure)"
- getContext.unit.warning(tree.pos, s"fruitless type test: a value of type $X cannot also be a $P$addendum")
+ getContext.unit.warning(tree.pos, s"fruitless type test: a value of type $X cannot also be a $PString$addendum")
}
else if (checker.isUncheckable) {
val msg = (
- if (checker.uncheckableType =:= P) s"abstract type $where$P"
- else s"${checker.uncheckableMessage} in type $where$P"
+ if (checker.uncheckableType =:= P) s"abstract type $where$PString"
+ else s"${checker.uncheckableMessage} in type $where$PString"
)
getContext.unit.warning(tree.pos, s"$msg is unchecked since it is eliminated by erasure")
}
diff --git a/test/files/neg/t3692-new.check b/test/files/neg/t3692-new.check
index 9b96449930..bb8692f3ca 100644
--- a/test/files/neg/t3692-new.check
+++ b/test/files/neg/t3692-new.check
@@ -1,10 +1,10 @@
-t3692-new.scala:14: warning: non-variable type argument Int in type pattern Map[Int,Int] is unchecked since it is eliminated by erasure
+t3692-new.scala:14: warning: non-variable type argument Int in type pattern scala.collection.immutable.Map[Int,Int] (the underlying of Map[Int,Int]) is unchecked since it is eliminated by erasure
case m0: Map[Int, Int] => new java.util.HashMap[Integer, Integer]
^
-t3692-new.scala:15: warning: non-variable type argument Int in type pattern Map[Int,V] is unchecked since it is eliminated by erasure
+t3692-new.scala:15: warning: non-variable type argument Int in type pattern scala.collection.immutable.Map[Int,V] (the underlying of Map[Int,V]) is unchecked since it is eliminated by erasure
case m1: Map[Int, V] => new java.util.HashMap[Integer, V]
^
-t3692-new.scala:16: warning: non-variable type argument Int in type pattern Map[T,Int] is unchecked since it is eliminated by erasure
+t3692-new.scala:16: warning: non-variable type argument Int in type pattern scala.collection.immutable.Map[T,Int] (the underlying of Map[T,Int]) is unchecked since it is eliminated by erasure
case m2: Map[T, Int] => new java.util.HashMap[T, Integer]
^
t3692-new.scala:15: warning: unreachable code
diff --git a/test/files/neg/t7984.check b/test/files/neg/t7984.check
new file mode 100644
index 0000000000..0cfd7d1619
--- /dev/null
+++ b/test/files/neg/t7984.check
@@ -0,0 +1,6 @@
+t7984.scala:4: warning: non-variable type argument Int in type pattern List[Int] (the underlying of Test.this.ListInt) is unchecked since it is eliminated by erasure
+ case is: ListInt => is.head
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
+one error found
diff --git a/test/files/neg/t7984.flags b/test/files/neg/t7984.flags
new file mode 100644
index 0000000000..e8fb65d50c
--- /dev/null
+++ b/test/files/neg/t7984.flags
@@ -0,0 +1 @@
+-Xfatal-warnings \ No newline at end of file
diff --git a/test/files/neg/t7984.scala b/test/files/neg/t7984.scala
new file mode 100644
index 0000000000..ca09a89fc7
--- /dev/null
+++ b/test/files/neg/t7984.scala
@@ -0,0 +1,7 @@
+class Test {
+ type ListInt = List[Int]
+ List[Any]("") match {
+ case is: ListInt => is.head
+ case _ =>
+ }
+}
diff --git a/test/files/neg/unchecked-suppress.check b/test/files/neg/unchecked-suppress.check
index 038105918e..d3dc86014b 100644
--- a/test/files/neg/unchecked-suppress.check
+++ b/test/files/neg/unchecked-suppress.check
@@ -1,7 +1,7 @@
-unchecked-suppress.scala:4: warning: non-variable type argument Int in type pattern Set[Int] is unchecked since it is eliminated by erasure
+unchecked-suppress.scala:4: warning: non-variable type argument Int in type pattern scala.collection.immutable.Set[Int] (the underlying of Set[Int]) is unchecked since it is eliminated by erasure
case xs: Set[Int] => xs.head // unchecked
^
-unchecked-suppress.scala:5: warning: non-variable type argument String in type pattern Map[String @unchecked,String] is unchecked since it is eliminated by erasure
+unchecked-suppress.scala:5: warning: non-variable type argument String in type pattern scala.collection.immutable.Map[String @unchecked,String] (the underlying of Map[String @unchecked,String]) is unchecked since it is eliminated by erasure
case xs: Map[String @unchecked, String] => xs.head // one unchecked, one okay
^
unchecked-suppress.scala:7: warning: non-variable type argument Int in type pattern (Int, Int) => Int is unchecked since it is eliminated by erasure
diff --git a/test/files/neg/unchecked.check b/test/files/neg/unchecked.check
index 570f02f219..033cffb18f 100644
--- a/test/files/neg/unchecked.check
+++ b/test/files/neg/unchecked.check
@@ -1,10 +1,10 @@
-unchecked.scala:18: warning: non-variable type argument String in type pattern Iterable[String] is unchecked since it is eliminated by erasure
+unchecked.scala:18: warning: non-variable type argument String in type pattern Iterable[String] (the underlying of Iterable[String]) is unchecked since it is eliminated by erasure
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
+unchecked.scala:22: warning: non-variable type argument Any in type pattern scala.collection.immutable.Set[Any] (the underlying of Set[Any]) is unchecked since it is eliminated by erasure
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
+unchecked.scala:26: warning: non-variable type argument Any in type pattern scala.collection.immutable.Map[Any,Any] (the underlying of Map[Any,Any]) is unchecked since it is eliminated by erasure
case xs: Map[Any, Any] => xs.head // unchecked
^
unchecked.scala:35: warning: non-variable type argument List[Nothing] in type pattern Test.Contra[List[Nothing]] is unchecked since it is eliminated by erasure
diff --git a/test/files/neg/unchecked3.check b/test/files/neg/unchecked3.check
index a7582a8930..0a526050fc 100644
--- a/test/files/neg/unchecked3.check
+++ b/test/files/neg/unchecked3.check
@@ -31,7 +31,7 @@ unchecked3.scala:62: warning: non-variable type argument Array[String] in type p
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
+unchecked3.scala:75: warning: abstract type A in type pattern scala.collection.immutable.Set[Q.this.A] (the underlying of 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