Community
Participate
Working Groups
The following program has started compiling with out any errors on 1.7 (JDK 7b142 compiles this). class A {} class B<V> extends A {} class F<T extends A, Y extends B<T>> { static <U extends A , V extends B<U>> F<U,V> g() { return null; } } public class X { F<? extends B, ? extends B<? extends B>> f011 = F.g(); } It used to fail to compile with JDK 6 with the message: X.java:9: incompatible types; inferred type argument(s) B,B<? extends B> do not conform to bounds of type variable(s) U,V found : <U,V>F<U,V> required: F<? extends B,? extends B<? extends B>> F<? extends B, ? extends B<? extends B>> f011 = F.g(); ^ 1 error JDK5 compiles this alright. Eclipse top of trunk BETA_JAVA7 fails with a message: Bound mismatch: The generic method g() of type F<T,Y> is not applicable for the arguments (). The inferred type B<? extends B>&B<B> is not a valid substitute for the bounded parameter <V extends B<U>> This difference needs to be understood as in the context of java 7 this impacts <> usage also.
I'll investigate this.
Released disabled junit org.eclipse.jdt.core.tests.compiler.regression.GenericsRegressionTest._test347145() into BETA_JAVA7 branch.
(In reply to comment #0) > The following program has started compiling with out any > errors on 1.7 (JDK 7b142 compiles this). [...] > It used to fail to compile with JDK 6 with the message: Olivier, can you check against different versions of JDK7 to have to see when exactly this started compiling alright ? (My hard-disk got replaced and I lost my cache of past builds of javac. (In any case, I had them only from 7b75 or so)) - TIA.
Created attachment 196844 [details] Early version of a fix.
Created attachment 196864 [details] Revised patch under test
(In reply to comment #3) > Olivier, can you check against different versions of JDK7 > to have to see when exactly this started compiling alright ? Please ignore this request - I have figured out what the problem is: The error message offers a good clue as to what is happening here: "The inferred type B<? extends B>&B<B> is not a valid substitute for the bounded parameter <V extends B<U>>" The intersection type "B<? extends B>&B<B>" looks strange. Why isn't simply B<B> since B<? extends B> is a superset if B<B> ? This is because after one round, we infer <U extends A> to be B#RAW <V extends B<U>> to be B<? extends B#RAW>&B<U> At this point neither of the intersecting types look like a subset of the other. However once we remove the lingering reference to U the intersecting types become "B<? extends B>&B<B>" with a clear subset relationship. The fix is to recognize the fact after we apply the final round of substitutions to remove any lingering type variable references, we should re-evaluate intersection types suitably.
Released in BETA_JAVA7 branch. Olivier, please review - TIA.
(In reply to comment #6) > The fix is to recognize the fact after we apply the final round of > substitutions to remove any lingering type variable references, we > should re-evaluate intersection types suitably. And propagate the altered type back to the inference context. See bug 347746.
Please ignore this code review request, This fix is being subsumed by the better fix being tested for bug 347600 for which I will raise a separate code review request.
Verified using Eclipse Java 7 Support(Beta) feature patch v20110623-0900.