Bug 83615

Summary: [1.5][compiler] lenient subclass checking with interdependent type variables
Product: [Eclipse Project] JDT Reporter: Tom Hofmann <eclipse>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:

Description Tom Hofmann CLA 2005-01-25 10:06:40 EST
jdt-core of 20050125

the following snippet compiles, javac gives:

.../test1/DependentParameters.java:10: <Q,L>nextTry(Q,L) in
test1.DependentParameters cannot be applied to (java.lang.Integer,java.lang.Number)
		new DependentParameters().nextTry(i, n);
                ^
1 error

-------- snip ---------

package test1;

public class DependentParameters {

	public static void main(String[] args) {
		Number n= null;
		Integer i= null;
		new DependentParameters().nextTry(i, n);
	}	
	
	<Q,L extends Q> void nextTry(Q q, L l) {	
	}
	
}
Comment 1 Tom Hofmann CLA 2005-02-03 06:34:32 EST
Actually the solution eclipse finds seems correct as well - it resolves both Q
and L to java.lang.Number. This fulfills both "L extends Q" as well as "Integer
isa Number" and "Number isa Number" for the parameters.

Not sure what the spec says.
Comment 2 Philipe Mulet CLA 2005-02-03 07:02:56 EST
During type inference, we indeed infer that Q is Number and not Integer.
Comment 3 Philipe Mulet CLA 2005-02-04 06:35:04 EST
Unfortunately, spec says we should not be that clever. We did check the variable
bound (L extends Q) in first inference pass, to collect possible candidates; but
we should only consider doing so in a later stage, when there was no match for Q.

Comment 4 Philipe Mulet CLA 2005-02-07 10:27:49 EST
Adjusted type argument inference support to defer bound check to later stage. So
if candidate is found during method argument inference, it will prevail.

Added GenericTypeTest#test494.
Fixed
Comment 5 Jerome Lanneluc CLA 2005-02-15 07:21:56 EST
Verified in I20050214