Bug 254627

Summary: [1.5][compiler] Eclipse does not consider an error when javac does on partially typed
Product: [Eclipse Project] JDT Reporter: Zorzella Mising name <zorzella>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann, philippe_mulet
Version: 3.5   
Target Milestone: 3.5 M5   
Hardware: All   
OS: All   
Whiteboard:

Description Zorzella Mising name CLA 2008-11-07 12:57:17 EST
Build ID: I20080617-2000

See simple code below. It compiles under Eclipse, but neither of the calls to "buz" pass javac. "baz" is only presented as a frame of reference, since javac and Eclipse seem to agree on that.

******************************

import java.util.List;

public class Foo {

  private static class C {}
  private static class B<T extends C> {}
  private static class A<T extends B<? extends C>> {}
  
  void bar (List<A> a) {
    baz((List)a);
    
    // Neither of these two following statements compile under javac
    buz(a);
    buz((List)a);
    
    // Side note: the following statement is correctly identified as an error
    // by Eclipse, but it does not suggest casting as a Quick Fix.
    // baz(a);
  }

  <R extends C, T extends B<R>> void baz(List<A<T>> a) {}
  <R extends C, T extends B<R>> void buz(List a) {}
  
}
Comment 1 Philipe Mulet CLA 2009-01-22 04:23:50 EST
I suspect this is a bug in javac, where the inference in JLS 15.12.2.8 doesn't properly exploit formal upper bounds. This combined with JLS 15.12.2.6 (unchecked conversion involved in invocation arguments) is likely accounting for the difference in behavior for javac between #baz(...) and #buz(...) invocations.

I believe both invocations are fine, and we should accept them.
Comment 2 Philipe Mulet CLA 2009-01-22 04:28:42 EST
Added GenericTypeTest#test1443.
Closing as invalid.
Comment 3 Philipe Mulet CLA 2009-01-22 05:02:46 EST
Re: // but it does not suggest casting as a Quick Fix.

Quickfix is only trying to fix code correctly. The quickfix you suggested would turn bad code in unsafe code; resulting into an unchecked invocation warning.
It should rather be turned into correct code, which cannot be trivially determined here.
Comment 4 Frederic Fusier CLA 2009-01-27 07:11:39 EST
Verified for 3.5M5