Bug 135234

Summary: Conditional operand types incorrectly rejected by compiler in 1.3 and 1.4 compliance mode
Product: [Eclipse Project] JDT Reporter: Fares Abdullah <fares.abdullah>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2   
Target Milestone: 3.2 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

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.