Bug 111086 - [1.5][compiler] Compiler accepts call to parameterized method with invalid arguments
Summary: [1.5][compiler] Compiler accepts call to parameterized method with invalid ar...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.3 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-29 12:14 EDT by Markus Keller CLA
Modified: 2006-08-08 05:20 EDT (History)
0 users

See Also:


Attachments
Proposed patch (73.56 KB, patch)
2006-06-23 19:16 EDT, Philipe Mulet CLA
no flags Details | Diff
Better patch (69.99 KB, patch)
2006-06-25 17:28 EDT, 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 Markus Keller CLA 2005-09-29 12:14:08 EDT
I20050928-1300

from http://forum.java.sun.com/thread.jspa?threadID=664224 :

class SortedList<E extends Comparable> extends LinkedList<E>
{
    public boolean add(E e){
      int index = Collections.binarySearch(this,e);
      if (index<0)
      super.add(-index-1,e);
      return true;
  }
}

Peter Ahe says this should not compile, unless the declaration is changed to:
public class SortedList<E extends Comparable<E>> extends LinkedList<E>
Comment 1 Philipe Mulet CLA 2006-06-22 04:21:33 EDT
From spec 15.12.2.7, the inference performs like this:

&#10070; A << F
   A is X<E>, F is List<? extends Comparable<? super T>>

&#10070; If F has the form G<..., Yk-1, ? extends U, Yk+1, ...>, where U involves Tj,
then if A has a supertype that is one of:
  U is Comparable<? super T>

  &#10019; G<..., Xk-1, V, Xk+1, ...>, where V is a type expression. Then this algorithm
  is applied recursively to the constraint V << U.

   X<E> << List<? extends Comparable<? super T>>
   Matching supertype for A is List<E>
   Recursing into:
   E << Comparable<? super T>

&#10070; A << F
   A is E, F is Comparable<? super T>

&#10019; If F has the form G<..., Yk-1, ? super U, Yk+1, ...>, where U involves Tj,
then if A has a supertype that is one of:
  U is T

  &#10019; Otherwise, no constraint is implied on Tj  ????

Our implementation is handling raw types (for A) at this point, but slightly differently than javac as it seems.
I am not aware of any spec'ed behavior describing the handling of inference against raw types (ie. inject erasure of arguments? etc...).
Comment 2 Philipe Mulet CLA 2006-06-23 19:12:13 EDT
Tuned semantics to refuse inferring from raw types at depth > 0.
Added GenericTypeTest#test1017
Comment 3 Philipe Mulet CLA 2006-06-23 19:16:55 EDT
Created attachment 45226 [details]
Proposed patch

Patch contains a little more than just this fix.
Comment 4 Philipe Mulet CLA 2006-06-25 17:28:01 EDT
Created attachment 45270 [details]
Better patch
Comment 5 Philipe Mulet CLA 2006-06-25 17:28:59 EDT
Released fix for 3.3M1 (HEAD)
Comment 6 Philipe Mulet CLA 2006-06-25 17:34:09 EDT
The fix is quite extensive, this is why not released to 3.2.1, as it got categorized minor to start with.
Comment 7 Frederic Fusier CLA 2006-08-08 05:20:58 EDT
Verified for 3.3 M1 using build I20060807-2000.