Bug 76219

Summary: [1.5][wildcards] Not-necessarily-unbounded wildcards in method formal parameter types
Product: [Eclipse Project] JDT Reporter: John Maraist <from-eclipse>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: BJGeraci
Version: 3.1   
Target Milestone: 3.1 M3   
Hardware: PC   
OS: All   
Whiteboard:

Description John Maraist CLA 2004-10-13 19:55:56 EDT
System: 
 - Eclipse 3.1M2  
 - Mandrake 10.0 
 
This code exhibits inconsistant behavior on the Sun and Eclipse 
compilers. 
 
  interface AA<W, Z extends AA<W, Z>> { 
    public boolean m(AA<W, ?> that); 
    public Z z(); 
    public boolean b(); 
  } 
 
  abstract class BB<U, V extends AA<U, V>> implements AA<U,V> { 
    public boolean m(AA<U, ?> wht) { return wht.z().b(); } 
  } 
 
Note that 
 
 - The formal type parameter Z of AA is bounded 
   recursively by AA, 
 
 - But the corresponding type argument of the 
   declared type of formal parameter wht of 
   method m's implementation is a wildcard 
   with no bound. 
 
My understanding of unbounded wildcards is as an implicit 
bound of Object, which in this case means that in the 
body of m the expression "wht.z()" should be assumed to 
be Object, which does not have a method b().  The Eclipse 
compiler seems to reject this code for this reason:"'Bound 
mismatch: the type ? is not a valid substitute for the 
bounded parameter <Z extends AA<W,Z>> of type AA<W,Z>". 
 
On the other hand, any validly constructed actual 
parameter wht of type AA<U, ?> would certainly have 
been constructed respecting the bounds on Z.  Perhaps 
this is why the Sun JDK javac accepts this code without 
error? 
 
I do not know which is the correct behavior, and am 
posting this bug to both the JDK and Eclipse bug 
pages. 
 
(Interface AA, by itself, compiles without error 
on both compilers.)
Comment 1 Frederic Fusier CLA 2004-10-27 10:19:07 EDT
JDT compiler still complains with last build I200410260800:
----------
1. ERROR in D:\usr\OTI\workspaces\dvpt\v31\HEAD\_Bug\BB.java (at line 2)
	public boolean m(AA<U, ?> wht) { return wht.z().b(); } 
	                       ^
Bound mismatch: The type ? is not a valid substitute for the bounded parameter
<Z extends AA<W,Z>> of the type AA<W,Z>
----------
1 problem (1 error)
Comment 2 Philipe Mulet CLA 2004-11-02 09:23:04 EST
Added regression test: GenericTypeTest#test378.
Comment 3 Philipe Mulet CLA 2004-11-02 09:23:56 EST
Rewrote the type argument comparisons.
Fixed
Comment 4 Frederic Fusier CLA 2004-11-04 11:42:30 EST
Verified for 3.1 M3 with build I200411040800