Bug 135234 - Conditional operand types incorrectly rejected by compiler in 1.3 and 1.4 compliance mode
Summary: Conditional operand types incorrectly rejected by compiler in 1.3 and 1.4 com...
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 RC1   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-06 06:03 EDT by Fares Abdullah CLA
Modified: 2006-04-06 10:30 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 Fares Abdullah CLA 2006-04-06 06:03:07 EDT
Reproduced with Eclipse 3.2M6 on Windows XP, but also reproduced by a colleague (i.e. uncomfirmed) on Eclipse 3.1.2
Running on Sun JDK 1.5.0

This is not a problem in the 5.0 compiler compliance level.

Set the compliance level to 1.3 or 1.4 (with default compliance settings), and put the following classes in a project:

public interface I {
}

public class A implements I {
}

public class B implements I {
}

public class Test {
	public static void main(String[] args) {
		I i = true ? new A() : new B();
	}
}

The ternary operator line shows an error and says "Incompatible conditional operand types A and B"
Comment 1 Fares Abdullah CLA 2006-04-06 06:17:19 EDT
Actually, this may (oddly) be the "correct" behavior. The Sun 1.5 JDK's javac shows the same error in 1.4 compliance mode, but not in default compliance mode (1.5).

This bug may be invalid.
Comment 2 Philipe Mulet CLA 2006-04-06 10:30:15 EDT
Yes, this behavior is intended. With Java5, the compiler is now inferring most specific common supertype, in 1.4 you had to tell him explicitly (i.e. inserted a cast to (I) on one operand).

Working as intended.