Bug 81831 - [1.5][compiler] JDT compiler tries to infer the wildcard type "too early" in case of recursive generic type-bounds
Summary: [1.5][compiler] JDT compiler tries to infer the wildcard type "too early" in ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-22 17:41 EST by Irfan Adilovic CLA
Modified: 2005-05-11 10:08 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Irfan Adilovic CLA 2004-12-22 17:41:11 EST
Compilation of the following interface fails:
    interface I<T extends I<? super T>> {}
with:
    "Bound mismatch: The type ? super T is not a valid substitute for the
bounded parameter <T extends I<? super T>> of the type I<T>"

The compiler tries to assure that the *eventual* substitute of "? super T" is
valid by checking it against the original bound of I: "T extends I<...>".

The proper way is to check the *implementers* of this interface to assure that
their proposed type parameters are within bounds, not the bound definition
itself. The code should only fail if it could be guaranteed that no implementer
may satisfy the bounds (which is obviously not the case here)

Note 1: compiling with javac -Xlint:all gives no warnings or errors whatsoever.

Note 2: interestingly, following compiles, although it *should* be in the same
category as the code above:
    interface I<T extends I< ? extends T>> {}
Interestingly as well,
    interface I<T extends I< ? super I>> {}
compiles in contrast to javac, but
    class I<T extends I< ? super I<?>>> {}
does not compile in agreement with javac.

Node 3: Sun's javac (5.0) is problematic too, try
    interface I<T extends I<? extends I<? super T>>> {}
for a funny 1029 line long stack trace of a stack overflow.

-- Irfy
Comment 1 Irfan Adilovic CLA 2004-12-22 19:33:45 EST
Correction for Note 3: Taking my words back about the compiler, after updating
to JDK 1.5.0_01 :-). It now works with SUN's javac, but Eclipse still does not
accept it.

For the curious, the stack overflow can be reproduced with JDK 1.5.0-rc

-- Irfy
Comment 2 Philipe Mulet CLA 2005-04-12 06:01:05 EDT
Bound checks still need to occur when resolving type parameter bounds. I suspect
it just needs some tuning.
Comment 3 Philipe Mulet CLA 2005-04-16 08:21:42 EDT
Fixed by tuning bound check wrt to super wildcard.
Added GenericTypeTest#test609.
Comment 4 Philipe Mulet CLA 2005-04-16 08:22:10 EDT
Fixed
Comment 5 Philipe Mulet CLA 2005-04-21 09:11:36 EDT
Released
Comment 6 Olivier Thomann CLA 2005-05-11 10:08:43 EDT
Verified in I20050510-0010