From 756e551b30461b548ea59e99562634775b7ebd74 Mon Sep 17 00:00:00 2001 From: Antoine Gourlay Date: Thu, 31 Jul 2014 17:52:13 +0200 Subject: 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 --- test/files/neg/t6675b.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/files/neg/t6675b.scala') diff --git a/test/files/neg/t6675b.scala b/test/files/neg/t6675b.scala index c86c9c3955..da27e1b91f 100644 --- a/test/files/neg/t6675b.scala +++ b/test/files/neg/t6675b.scala @@ -13,7 +13,7 @@ object NativelyTwo { } -class A { +class E { def f1 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight(a) => a } // warn def f2 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight((a, b)) => a } // no warn def f3 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight((a, b, c)) => a } // fail -- cgit v1.2.3