diff options
author | Antoine Gourlay <antoine@gourlay.fr> | 2014-07-31 17:52:13 +0200 |
---|---|---|
committer | Antoine Gourlay <antoine@gourlay.fr> | 2014-08-12 15:47:20 +0200 |
commit | 756e551b30461b548ea59e99562634775b7ebd74 (patch) | |
tree | 678fd556b17768d1cf533135bbfd1741df025d8d /test/files/neg/t5691.check | |
parent | 84d4ebc19a1e54dbe446ef35b71efa7ad3890c19 (diff) | |
download | scala-756e551b30461b548ea59e99562634775b7ebd74.tar.gz scala-756e551b30461b548ea59e99562634775b7ebd74.tar.bz2 scala-756e551b30461b548ea59e99562634775b7ebd74.zip |
SI-5691 lint warning when a type parameter shadows an existing type.
This adds a new lint warning for when a class/method/type-member's
type parameter shadows an existing type: `-Xlint:type-parameter-shadow`.
It excludes type parameters of synthetic methods (the user can't
rename or remove those anyway), otherwise, for example, every case class
triggers the warning.
Also fixes a test that contained wrong java sources (that didn't even
compile...), discovered thanks to the warning.
---
This kind of errors shows up every now and then on the mailing-list, on
stackoverflow, etc. so maybe a warning would be useful.
I was afraid this would yield too many warnings for libraries that are
heavy on type parameters, but no: running this on scalaz and shapeless
HEAD (`v7.1.0-RC1-41-g1cc0a96` and `v2.0.0-M1-225-g78426a0` respectively)
yields 44 warnings. None of them are false positives; they usually come
from:
- scalaz loving using `A` as type parameter, even several levels deep
of parametrized classes/methods
- or calling a type parameter that will hold a map `Map`, or similar,
thus shadowing an existing type
Diffstat (limited to 'test/files/neg/t5691.check')
-rw-r--r-- | test/files/neg/t5691.check | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/files/neg/t5691.check b/test/files/neg/t5691.check new file mode 100644 index 0000000000..a51ca98a10 --- /dev/null +++ b/test/files/neg/t5691.check @@ -0,0 +1,24 @@ +t5691.scala:7: warning: type parameter D defined in method foobar shadows trait D defined in class B. You may want to rename your type parameter, or possibly remove it. + def foobar[D](in: D) = in.toString + ^ +t5691.scala:10: warning: type parameter D defined in type MySeq shadows trait D defined in class B. You may want to rename your type parameter, or possibly remove it. + type MySeq[D] = Seq[D] + ^ +t5691.scala:15: warning: type parameter T defined in method bar shadows type T defined in class Foo. You may want to rename your type parameter, or possibly remove it. + def bar[T](w: T) = w.toString + ^ +t5691.scala:13: warning: type parameter T defined in class Foo shadows type T defined in class B. You may want to rename your type parameter, or possibly remove it. + class Foo[T](t: T) { + ^ +t5691.scala:19: warning: type parameter List defined in type M shadows type List defined in package object scala. You may want to rename your type parameter, or possibly remove it. + class C[M[List[_]]] + ^ +t5691.scala:20: warning: type parameter List defined in type M shadows type List defined in package object scala. You may want to rename your type parameter, or possibly remove it. + type E[M[List[_]]] = Int + ^ +t5691.scala:21: warning: type parameter List defined in type M shadows type List defined in package object scala. You may want to rename your type parameter, or possibly remove it. + def foo[N[M[List[_]]]] = ??? + ^ +error: No warnings can be incurred under -Xfatal-warnings. +7 warnings found +one error found |