Bug 257434 - [1.5][compiler] Should detect type mismatch after capture
Summary: [1.5][compiler] Should detect type mismatch after capture
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4.2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-03 15:49 EST by Philipe Mulet CLA
Modified: 2009-02-03 12:24 EST (History)
2 users (show)

See Also:
jerome_lanneluc: review+


Attachments
Work in progress (17.28 KB, patch)
2008-12-04 12:00 EST, Philipe Mulet CLA
no flags Details | Diff
Proposed patch (17.08 KB, patch)
2008-12-04 12:43 EST, Philipe Mulet CLA
no flags Details | Diff
Proposed patch for 3.4 (25.52 KB, patch)
2008-12-05 10:40 EST, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2008-12-03 15:49:12 EST
Build 3.5M3

The following code should be rejected by the compiler:

class Box<U extends Box<?, ?>, V extends U> {
	V value;
	Box<U, V> same;
	Box(V v) {
		value = v;
	}
	Box() {
	}
}
class A extends Box<A, A> {}
class B extends Box<B, B> {}
public class X {
	public static void main(String[] args) {
		Box<Box<A, A>, Box<A, A>> a = new Box<Box<A, A>, Box<A, A>>(new Box<A, A>(new A()));
		Box<?, ?> b = a;
		b.value.same = new Box<B, B>(new B());
		A c = a.value.same.value;
	}
}

Also see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6450290
Comment 1 Philipe Mulet CLA 2008-12-04 12:00:30 EST
Created attachment 119528 [details]
Work in progress

This patch GenericTypeTest#test0925 and it should not.
It complains about an ambiguous call.

		"----------\n" + 
		"1. ERROR in X.java (at line 23)\n" + 
		"	l.addAll(getRelated(b));\n" + 
		"	  ^^^^^^\n" + 
		"The method addAll(Collection<? extends capture#2-of ? super A>) is ambiguous for the type L\n" + 
		"----------\n"

Before the patch, the method didn't get captured argument types; which wasn't good.
Comment 2 Philipe Mulet CLA 2008-12-04 12:43:26 EST
Created attachment 119531 [details]
Proposed patch

This addresses the previous concern. When iterating supertypes, need to hold onto the already captured receiver type.
Comment 3 Philipe Mulet CLA 2008-12-05 07:41:53 EST
Released for 3.5M4.
Fixed
Comment 4 Philipe Mulet CLA 2008-12-05 09:02:17 EST
Added GenericTypeTest#test1418-1420
Comment 5 Philipe Mulet CLA 2008-12-05 10:40:03 EST
I believe we should consider fixing it for 3.4.2. There is no workaround, and the compiler is exposing uncaptured wildcards which can lead to accept illegal code by mistake.

Fix is reasonable.
Comment 6 Philipe Mulet CLA 2008-12-05 10:40:49 EST
Created attachment 119629 [details]
Proposed patch for 3.4
Comment 7 Jerome Lanneluc CLA 2008-12-05 11:02:03 EST
Note that patch from comment 6 contains a fix in AbstractImageBuilder for another bug. It should not be part of this patch.

Other than that, +1 for 3.4.2
Comment 8 Philipe Mulet CLA 2008-12-05 11:05:36 EST
Good point. I will not commit this part.
Comment 9 Philipe Mulet CLA 2008-12-05 11:05:54 EST
Released for 3.4.2
Comment 10 Jerome Lanneluc CLA 2008-12-09 06:49:03 EST
Verified for 3.5M4 using I20081209-0100
Comment 11 Kent Johnson CLA 2009-02-03 12:24:08 EST
Verified for 3.4.2 using M20090127-1710