Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 216558

Summary: [1.5][compiler] Method inference produces misleading errors
Product: [Eclipse Project] JDT Reporter: Philipe Mulet <philippe_mulet>
Component: CoreAssignee: 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 CLA 2008-01-25 05:18:34 EST
Build 3.4M4

Also reported against javac as http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6568599

In following program, it feels like inference could have inferred T==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<?, ?>> {
	}
}
Comment 1 Philipe Mulet CLA 2008-01-25 05:24:01 EST
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-?>>
Comment 2 Philipe Mulet CLA 2008-01-25 05:33:23 EST
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>> {
        }
}


Comment 3 Philipe Mulet CLA 2008-01-25 05:34:58 EST
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<?, ?>> {
	}
}

Comment 4 Philipe Mulet CLA 2008-01-25 05:39:26 EST
Added GenericTypeTest#1247-1249
Comment 5 Philipe Mulet CLA 2008-01-25 05:47:27 EST
In comment 3, the line: 
    eval(foo, foo); // fails

should read:
    eval(foo, foo); // no longer fails
Comment 6 Eclipse Genie CLA 2020-03-29 05:41:53 EDT
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.
Comment 7 Stephan Herrmann CLA 2020-03-29 08:07:40 EDT
Concerning comment 0, ecj and javac agree on both:
- rejecting at 1.7
- accepting at 1.8+

All is good.