Bug 284906 - [1.5] [compiler] Error in type checking for generics
Summary: [1.5] [compiler] Error in type checking for generics
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M1   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-28 13:47 EDT by Konstantin Titorenko CLA
Modified: 2009-08-03 06:26 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Titorenko CLA 2009-07-28 13:47:12 EDT
Build ID: 20090619-0625

Steps To Reproduce:
1. Compile following code in Eclipse:

public class Test {
  void doStuff(IGenericReference<? extends ISpecificReference> reference) {
    new Delegate().doStuff(reference);
  }
}

class Delegate {
  void doStuff(IGenericReference<? extends ISpecificReference> reference) {
  }
}

interface IGenericReference<T extends IGenericReference<T>> {}

interface ISpecificReference {}

2. Compile same code with Sun javac -> error

3. Eclipse should be able peak the problem with ISpecificReference (it is not extending IGenericReference)

More information:
Comment 1 Stephan Herrmann CLA 2009-07-28 16:54:47 EDT
(In reply to comment #0)
> 2. Compile same code with Sun javac -> error

I don't see any error when compiling with Sun javac.
I have javac 1.6.0_13, which version were you using?
Comment 2 Konstantin Titorenko CLA 2009-07-28 20:50:00 EDT
Indeed, it compiles on 1.6.0_14. The error appears for sure on 1.5.0_12 and on 1.5.0_19:

javac -version Test.java
javac 1.5.0_19
Test.java:3: doStuff(IGenericReference<? extends ISpecificReference>) in Delegate cannot be applied to (IGenericReference<capture of ? extends ISpecificReference>)
    new Delegate().doStuff(reference);
    ^
1 error

Code is unfortunatelly quite complicated, not sure now if it was a genuine error in eclipse compiler. If you don't see any problem with code, please resolve the bug (as invalid, I guess).
Comment 3 Konstantin Titorenko CLA 2009-07-28 21:02:34 EDT
OK, slightly modified code doesn't compile on 1.6.0_14, but still compiles on eclipse:

public class Test {
  void doStuff(GenericReference<? extends SpecificReference> reference) {
    new Delegate().doStuff(reference);
  }
}

class Delegate {
  void doStuff(GenericReference<? extends SpecificReference> reference) {
  }
}

class GenericReference<T extends GenericReference<T>> {}

class SpecificReference {}

Logically, it looks like 1.6 working correct. In previous version SpecificReference was an interface and it was possible for some type to implement both Specific and Generic one (1.5 has not accounted for that), but for classes it is not possible (eclipse compiler has not accounted for that).
Comment 4 Konstantin Titorenko CLA 2009-07-28 21:12:24 EDT
Sorry, ignore previous posting eclipse compiler works in the same way as Sun 1.6 
Problem is only on 1.5 versions. 
Comment 5 Kent Johnson CLA 2009-07-29 11:21:45 EDT
Compiles fine with javac 6 & 7, and eclipse

Believe this was a bug in 1.5
Comment 6 Srikanth Sankaran CLA 2009-08-03 06:26:30 EDT
Verified for 3.6M1