Bug 76219 - [1.5][wildcards] Not-necessarily-unbounded wildcards in method formal parameter types
Summary: [1.5][wildcards] Not-necessarily-unbounded wildcards in method formal paramet...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.1 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-13 19:55 EDT by John Maraist CLA
Modified: 2004-11-04 11:42 EST (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 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