Community
Participate
Working Groups
While using generic covariant as in class below, return a compile time error in eclipse 3.3.1 at line SubInterface sub3 = sub1.and(sub2); However, it compiles fine with Sun JDK 1.5.0_06. package test; public class TestEclipseCovariant { public static void testCovariant(SubInterface sub1, SubInterface sub2) { SubInterface sub3 = sub1.and(sub2); } public interface SuperInterface<E> { public Number getNumber(); public SuperInterface<E> and(SuperInterface<E> a); } public interface SubInterface extends SuperInterface { public Integer getNumber(); public SubInterface and(SuperInterface s); } }
Reproduced with latest. Thanks for the testcase. Our lookup seems to pick the superclass method by mistake.
Lookup properly isolates the following 2 candidates: 1. X.SubInterface and(SuperInterface#RAW) 2. SuperInterface#RAW and(SuperInterface#RAW) but tiebreak (Scope#mostSpecificMethodBinding(...)) decides (2) is the best match. I believe the problem is coming from Scope#isAcceptableMethod(...) which seems to reject the scenario where both methods have identical types, and original super method argtype wasn't raw. I don't get what this test is intending to achieve. Deleting the check makes the problem go away. Didn't find any regression in existing tests. Kent - what do you think ?
Created attachment 87394 [details] Proposed patch
Oops, there is a regression in AmbiguousMethodTest#test014h.
Instead of removing the 5 lines from Scope, I suggest we change it to: if (oneParam == twoParam) { if (twoParam.leafComponentType().isRawType()) { // must detect & reject this case // when Y<U> extends X<U> // void foo(Y y) {} // <T extends X<Object>> void foo(T t) {} // foo(T) will show up as foo(Y#RAW) and not foo(X#RAW) // Y#RAW is not more specific than a rawified X<T> if (twoParam.leafComponentType().erasure() != two.original().parameters[i].leafComponentType().erasure()) return false; } continue; }
But now, we would fail to accept the following code: public class X { <T extends G<X>> void a3(T x) {} <T extends F<X>> void a3(T x) {} public static void ambiguousCases() { H<X> hx = null; H hraw = null; new X().a3(hx); new X().a3(hraw); } } class F<T1> {} class G<T2> extends F<T2> {} class H<T3> extends G<T3> {}
Created attachment 87506 [details] Better patch Here is a patch which addresses the latter issue.
Added GenericTypeTest#test1232-1241. Kent - what do you think ?
looks good
Released for 3.4M5. Fixed
This is a regression over 3.2.2. Candidating for 3.3.2. Jerome ?
Asking for PMC approval to backport to 3.3.2 since: - valid code is rejected - this is a regression comparing to 3.2.2 - the fix is simple
+1 for 3.3.2
Released for 3.3.2 (same patch) Fixed
Verified for 3.3.2 using build M20080123-0800
Verified for 3.4M5 using I20080204-0010