Community
Participate
Working Groups
Build 3.4M2 On following example, due to method redundant definitions, the compiler reports unresolved references to type parameter R within method bodies. From the inside, the offending method binding should be preserved when diving into its body resolution. In presence of duplicates, it also seems like we should keep one binding to minimize incidence from the outside. public class X { public static <S, T extends Comparable<S>, R extends S & T> R max(T arg1, S arg2) { return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2); } public static <T extends Comparable<S>, S, R extends S & Comparable<S>> R max(T arg1, S arg2) { return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2); } public static <T extends Comparable<S>, S, R extends Comparable<S>> R max(T arg1, S arg2) { return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2); } public static void main(String[] args) { } }
Errors currently reported. Observe (3) and (6) secondary errors which shouldn't appear. ---------- 1. ERROR in X.java (at line 2) public static <S, T extends Comparable<S>, R extends S & T> R max(T arg1, S arg2) { ^ Cannot specify any additional bound T when first bound is a type parameter ---------- 2. ERROR in X.java (at line 2) public static <S, T extends Comparable<S>, R extends S & T> R max(T arg1, S arg2) { ^^^^^^^^^^^^^^^^^^^ Method max(T, S) has the same erasure max(Comparable<T>, Object) as another method in type X ---------- 3. ERROR in X.java (at line 3) return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2); ^ R cannot be resolved to a type ---------- 4. ERROR in X.java (at line 6) public static <T extends Comparable<S>, S, R extends S & Comparable<S>> R max(T arg1, S arg2) { ^^^^^^^^^^ Cannot specify any additional bound Comparable<S> when first bound is a type parameter ---------- 5. ERROR in X.java (at line 6) public static <T extends Comparable<S>, S, R extends S & Comparable<S>> R max(T arg1, S arg2) { ^^^^^^^^^^^^^^^^^^^ Method max(T, S) has the same erasure max(Comparable<T>, Object) as another method in type X ---------- 6. ERROR in X.java (at line 7) return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2); ^ R cannot be resolved to a type ---------- 7. WARNING in X.java (at line 11) return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Type safety: Unchecked cast from Object to R ----------
Added GenericTypeTest#test1181
Created attachment 79152 [details] Proposed patch The patch matches the type variable name against the method declaration's type parameter nodes instead of relying on the method's binding.
Created attachment 79233 [details] Proposed patch with testcase This patch only uses the method declaration's nodes when the binding isn't set. fixed up GenericTypeTest test1181()
Released into HEAD
Verified for 3.4M3 using I20071029-0010 build.