Bug 67643 - [1.5] Incompatible conditional operand types
Summary: [1.5] Incompatible conditional operand types
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-17 10:56 EDT by Igor Fedorenko CLA
Modified: 2005-01-11 11:02 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Fedorenko CLA 2004-06-17 10:56:40 EDT
I do not know what JLS has to say about this, but the following code compiles by
javac 1.5 but not by cheetah. Error mesage is "Incompatible conditional operand
types C1 and C2"

--------------------------
package test.cheetah;
import java.util.ArrayList;
public class Test {
    private static class C1 extends ArrayList {
    }
    private static class C2 extends ArrayList {
    }
    ArrayList method(boolean param) {
        return param? new C1(): new C2();
    }
}
--------------------------

Note that javac 1.4.2 does not compile this code (error message "incompatible
types for ?: neither is a subtype of the other"). 

eclipse 200406111814, cheetah from CVS as of late afternoon June 16 EDT ;-)
Comment 1 Philipe Mulet CLA 2004-06-17 11:51:31 EDT
Interesting...
Comment 2 Igor Fedorenko CLA 2004-06-17 14:40:22 EDT
Out of curiosity, why eclipse/old javac complain about this? Target type of this
expression (ArrayList) is known and both C1 and C2 can be casted to that type,
so what's wrong whith that?
Comment 3 Philipe Mulet CLA 2004-06-30 07:59:24 EDT
Under JLS2, one of the operand has to be assignable to the other (i.e. C1 
assignable to C2 or reciprocal). It looks like JLS3 allow inference of most 
common supertype (which makes sense).
Comment 4 Philipe Mulet CLA 2004-06-30 07:59:57 EDT
New behavior is implemented from -source 1.5 on.
Comment 5 Philipe Mulet CLA 2004-06-30 10:13:18 EDT
Regression test added: Compliance_1_5#test080.
Comment 6 Philipe Mulet CLA 2004-06-30 10:13:36 EDT
Fixed