Bug 106936 - [1.5][compiler] Unoptimal lub computation
Summary: [1.5][compiler] Unoptimal lub computation
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 107193 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-08-13 09:39 EDT by Philipe Mulet CLA
Modified: 2005-09-26 11:40 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2005-08-13 09:39:15 EDT
Head from 8/11/2005

With fix for bug 105531 released, the following code now gets rejected:

public class X {
 	static <T> T foo(T t1, T t2) { return t1; }
 	public static void main(String[] args) {
		Number[] n = {}, n2, n3;
		Float[] f = {};
		Number n2 = foo(n, f);
 	}
}
Comment 1 Philipe Mulet CLA 2005-08-13 09:42:55 EDT
Fix for 105531 only affects the following situation:
public class X {
 	static <T> T foo(T t1, T t2) { return t1; }
 	public static void main(String[] args) {
		Number[] n = {}, n2, n3;
		Float[] f = {};
 		Number n3 = n != null ? n : f;
 	}
}

Since plain lub algorithm is used to infer the type of the conditional
expression (as used to interesect Number[] and Float[] for generic method
inference).

So this is wrong since 3.1.0, but revealed for conditional expression with fix
for bug 105531.
Comment 2 Philipe Mulet CLA 2005-08-13 09:48:54 EDT
When writing following code:

public class X {
 	static <T> T foo(T t1, T t2) { return t1; }
 	public static void main(String[] args) {
		Number[] n = {};
		Float[] f = {};
 		String s = foo(n, f);
 	}
}
Eclipse complains:
----------
4. ERROR in X.java
 (at line 10)
	String s = foo(n, f); 		
	       ^
Type mismatch: cannot convert from Object&Serializable&Cloneable to String
----------
where javac claims:
X.java:10: incompatible types
found   : java.lang.Number[]
required: java.lang.String
                String s = foo(n, f);

Indeed when computing lub(Number[], Float[]), it should infer Number[] rather
than Object$Serializable&Cloneable
Comment 3 Philipe Mulet CLA 2005-08-15 19:09:15 EDT
Improved LUB computation to handle reference array type, considering all
supertypes of an array type.

Added GenericTypeTest#test805.
Fixed
Comment 4 Olivier Thomann CLA 2005-08-17 09:30:13 EDT
*** Bug 107193 has been marked as a duplicate of this bug. ***
Comment 5 David Audel CLA 2005-09-21 10:34:24 EDT
Verified in I20050921-0010 for 3.2M2
Comment 6 Olivier Thomann CLA 2005-09-26 11:40:50 EDT
Verified for 3.1.1 using M20050923-1430.