Summary: | [1.5][compiler] Generic inference more lenient than JDK compiler | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | David Gates <gatesda> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | VERIFIED DUPLICATE | QA Contact: | |
Severity: | minor | ||
Priority: | P3 | ||
Version: | 3.1.1 | ||
Target Milestone: | 3.5 M5 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
David Gates
2005-11-28 14:11:17 EST
The difference occurs on second pass of inference, where the type expectation is taken into account. Need to check the spec. Assignment conversions are supposed to affect type inference, as it does in our compiler. Actually, it behaves the same without any array initializer. public class X<A> { <B extends Comparable<B>> X<B> newInstance() { return new X<B>(); } X<String>[] bugDemo() { X x = newInstance(); return new X[] { x }; } } Note that the following compiles fine. public class X<A> { <B extends Comparable<B>> B newInstance2(X<B> xb) { return null; } void foo() { X x = new X(); Comparable c = newInstance2(x); } } Added GenericTypeTest#test0960-0961. Closing as javac bug. Actually, this may be a bug in ECJ. JLS 15.12.2.6 seems to mention need for an erasure of return type if any unchecked conversion got performed during inference. This would mean javac is actually right. Reopening for more consideration. Given changes for bug 258798, we now report an error: 2. ERROR in X.java (at line 7) X x = newInstance(); ^^^^^^^^^^^ Bound mismatch: The generic method newInstance() of type X<A> is not applicable for the arguments (). The inferred type Comparable<Comparable<B>> is not a valid substitute for the bounded parameter <B extends Comparable<B>> Closing as dup *** This bug has been marked as a duplicate of bug 258798 *** Verified for 3.5M5 using build I20090127-0100. |