Bug 98393 - [1.5][compiler] ClassCastException attempting to cast from intersection type
Summary: [1.5][compiler] ClassCastException attempting to cast from intersection type
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-03 18:13 EDT by Tim Hanson CLA
Modified: 2005-06-10 11:42 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 Tim Hanson CLA 2005-06-03 18:13:58 EDT
Compile this example:

class Outer {
    void foo() {
    	Comparable<String> c = (java.util.List)bar(5, 5.0);
    }
    
    <T> T bar(T t1, T t2) { return t1; }
}

produces this error:

----------
1. ERROR in Y.java
 (at line 0)

        ^
Internal compiler error
java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.lookup.WildcardB
inding
        at org.eclipse.jdt.internal.compiler.ast.Expression.checkCastTypesCompat
ibility(Expression.java:328)
        at org.eclipse.jdt.internal.compiler.ast.CastExpression.resolveType(Cast
Expression.java:382)
        at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalD
eclaration.java:199)
        at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resol
veStatements(AbstractMethodDeclaration.java:415)
        at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatem
ents(MethodDeclaration.java:171)
        at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resol
ve(AbstractMethodDeclaration.java:393)
        at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDec
laration.java:1063)
        at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDec
laration.java:1112)
        at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.reso
lve(CompilationUnitDeclaration.java:305)
        at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:504)

        at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:329)

        at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.
java:2652)
        at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:1151)
        at org.eclipse.jdt.internal.compiler.batch.Main.main(Main.java:1056)

----------
1 problem (1 error)
Comment 1 Philipe Mulet CLA 2005-06-05 16:43:25 EDT
Added GenericTypeTest#test715.
Comment 2 Philipe Mulet CLA 2005-06-06 04:09:25 EDT
Wildcards/intersection types were sharing type variable code for reaching upper
bound through a cast.

Fixed
Comment 3 Frederic Fusier CLA 2005-06-07 11:36:09 EDT
Verified for 3.1 RC2 using build N20050607-0010 + JDT/Core HEAD
Comment 4 David Audel CLA 2005-06-10 11:42:21 EDT
Verified for 3.1 RC2 using build I20050610-0010