| Summary: | [1.5][compiler] Method inference produces misleading errors | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Philipe Mulet <philippe_mulet> |
| Component: | Core | Assignee: | Stephan Herrmann <stephan.herrmann> |
| Status: | CLOSED WORKSFORME | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | lefevrol, stephan.herrmann |
| Version: | 3.4 | ||
| Target Milestone: | 4.16 M1 | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
|
Description
Philipe Mulet
In first invocation "eval(foo)", the type of the argument (used for inference) is: Foo<capture#1-of-?, capture#2-of-?>, and JLS 15.12.2.7 determines that T is bound to Foo<capture#1-of-?, capture#2-of-?>. whereas in second invocation "X.<Foo<?, ?>> eval(foo)", no capture conversion occurs, hence T is bound to Foo<?,?> directly. Now the contract for T is <T extends Iterable<T>>. Given "Foo<S, T> extends Iterable<Foo<?, ?>>", it appears that only the second invocation passes the boundcheck, since one cannot prove: Foo<capture#1-of-?, capture#2-of-?> <: Iterable<Foo<capture#1-of-?, capture#2-of-?>> On original case, it can be addressed by better specifying the Foo supertype (i.e. Iterable<Foo<S, T>> instead of Iterable<Foo<?,?>>):
public class X {
public static void test() {
Foo<?, ?> foo = null;
eval(foo); // fails
X.<Foo<?, ?>> eval(foo);
}
public static <T extends Iterable<T>> void eval(T x) {
}
public static interface Foo<S, T> extends Iterable<Foo<S, T>> {
}
}
However, it feels inconsitent (as explained in http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6568599) that the following is accepted, since inference intersects 2 captured types into wildcard when performing glb(...). public class X { public static void test() { Foo<?, ?> foo = null; eval(foo, foo); // fails X.<Foo<?, ?>> eval(foo, foo); } public static <T extends Iterable<T>> void eval(T t1, T t2) { } public static interface Foo<S, T> extends Iterable<Foo<?, ?>> { } } Added GenericTypeTest#1247-1249 In comment 3, the line: eval(foo, foo); // fails should read: eval(foo, foo); // no longer fails This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |