Bug 95066

Summary: [1.5][compiler] Wrong Cast Allowed
Product: [Eclipse Project] JDT Reporter: Carlos Aydos <carlos_aydos>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: carlos_aydos
Version: 3.1   
Target Milestone: 3.1 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Carlos Aydos CLA 2005-05-12 19:53:14 EDT
The code underneath compiles when it should fail.
I tried it with M5 and M6.

public class TestCasting<S extends Comparable<S>> {
   public TestCasting() {
       S a = (S)(Integer)3; // this should fail
   }
}
Comment 1 Olivier Thomann CLA 2005-05-13 10:13:56 EDT
Still failing using M7 candidate.
Comment 2 Philipe Mulet CLA 2005-05-13 12:07:42 EDT
Added GenericTypeTest#test661-665.

Part of the issue was that when recursing on variable upper bound, it was
actually using the upper bound erasure, and the check for final type was not
strict enough.

Fixed
Comment 3 Frederic Fusier CLA 2005-05-27 10:09:10 EDT
Verified for 3.1 RC1 with build I20050527-0010.
Comment 4 Philipe Mulet CLA 2006-02-03 06:39:28 EST
Humm... actually I now think this code should be accepted, with unchecked warnings. Comparable<S> is not provably distinct from Comparable<Integer>.
Interestingly, removing the bounds on S declaration make javac accept this code.
Comment 5 Philipe Mulet CLA 2006-02-05 11:49:00 EST
Also see javac bugs in cast conversions:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6270087