Bug 202404

Summary: [1.5][compiler] Incorrect handling of type variable bounds issued by capture conversion
Product: [Eclipse Project] JDT Reporter: Philipe Mulet <philippe_mulet>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: david_audel, jerome_lanneluc, zorzella
Version: 3.4Flags: philippe_mulet: pmc_approved+
Target Milestone: 3.3.2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 203318    
Attachments:
Description Flags
work in progress
none
Proposed patch none

Description Philipe Mulet CLA 2007-09-06 05:03:28 EDT
Build 3.3.0

The following program shouldn't raise any compiler error:

[X.java]
class A {}
class D<U extends A, V extends U> {}
public class X {
	void foo() {
		D<?, ? super A> d1 = null;
		D<?, ? extends A> d2 = null;
	}
}

The compiler currently rejects d2 declaration:
----------
1. ERROR in X.java (at line 6)
	D<?, ? extends A> d2 = null;
	     ^^^^^^^^^^^
Bound mismatch: The type ? extends A is not a valid substitute for the bounded parameter <V extends U> of the type D<U,V>
----------
Comment 1 Philipe Mulet CLA 2007-09-06 05:04:39 EDT
(comment from spec lead)

Consider the generic type
   class D<X extends A, Y extends X>...

And the parameterized type
   D<?, ? super A>

which capture-converts to
   D<#1 extends A super null, #2 extends #1 super A>

This is legal because there is a possible instantiation for #1 and #2: A.

Now consider the parameterized type
   D<?, ? extends A>

which capture-converts to
   D<#1 extends A super null, #2 extends glb(A, #1) super null>

Whatever #1 is, it extends A by its own definition, so glb(A, #1) is 
trivially well-formed and #2 can be inhabited. So I think D<?, ? extends 
A> is legal.
Comment 2 Philipe Mulet CLA 2007-09-12 12:14:50 EDT
The bound check is not truly performing a capture conversion, and rather tries to emulate it (to avoid creating captures on the fly). This results in slight differences in behavior.

Investigating.
Comment 3 Philipe Mulet CLA 2007-09-12 12:15:31 EDT
Created attachment 78199 [details]
work in progress

This is not final. It breaks existing working scenarii.
Comment 4 Philipe Mulet CLA 2007-09-12 12:20:04 EDT
Added GenericTypeTest#test1158-1162
Comment 5 Philipe Mulet CLA 2007-09-13 15:22:25 EDT
Also see bug 159214
Comment 6 Philipe Mulet CLA 2007-09-13 16:13:16 EDT
Created attachment 78381 [details]
Proposed patch

Alternate solution, better aligned with existing story. Basically, it doesn't induce more captures to be created, but simply tune the bound check test to better emulate the true capture.

Note that this patch is combined with the changes for bug 159214 and bug 203318 since all these issues are intricated.
Comment 7 Philipe Mulet CLA 2007-09-13 18:29:30 EDT
Released for 3.4M2.
Fixed
Comment 8 Philipe Mulet CLA 2007-09-13 18:42:17 EDT
*** Bug 179902 has been marked as a duplicate of this bug. ***
Comment 9 David Audel CLA 2007-09-18 06:28:40 EDT
Verified for 3.4M2 using build I20070918-0010
Comment 10 Philipe Mulet CLA 2007-10-10 04:23:33 EDT
Released for 3.3.2
Fixed
Comment 11 Philipe Mulet CLA 2007-10-10 04:24:03 EDT
reopening to remove verify state
Comment 12 Philipe Mulet CLA 2007-10-10 04:24:30 EDT
Released for 3.3.2
Fixed
Comment 13 Maxime Daniel CLA 2007-10-29 12:41:17 EDT
Only adding Verified for 3.4M2 to the status whiteboard, since I believe this got lost.
Comment 14 Jerome Lanneluc CLA 2007-11-22 10:16:58 EST
The compiler semantics near capture conversion need to be tuned to match the spec. Without these changes, we see quite many corner cases failing to compile properly or being rejected incorrectly, and numerous customers starting to notice it.

Comment 15 Philipe Mulet CLA 2007-11-23 09:18:50 EST
+1 for 3.3.2
Comment 16 Frederic Fusier CLA 2008-01-24 07:09:02 EST
Verified for 3.3.2 using build M20080123-0800.