Bug 80630 - [1.5] Conditional expression unboxing should handle this case
Summary: [1.5] Conditional expression unboxing should handle this case
Status: VERIFIED 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 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-09 14:35 EST by Olivier Thomann CLA
Modified: 2005-02-15 07:29 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 Olivier Thomann CLA 2004-12-09 14:35:48 EST
Test case:
public class X {
	public static void main(String[] args) {
		boolean b = true;
		Character _Character = new Character(' ');
		char c = ' ';
		Integer _Integer = new Integer(2);
		if ((b ? _Character : _Integer) == c) {
			System.out.println("SUCCESS");
		} else {
			System.out.println("FAILURE");
		}
	}
}

javac can successfully compile it. It converts the _Character to its charValue()
and the _Integer to its intValue().

We fail with:

----------
1. ERROR in C:\tests_sources\X.java (at line 7)
	if ((b ? _Character : _Integer) == c) {
	    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Incompatible operand types Object and char
----------
1 problem (1 error)

Note that it doesn't work anymore if you extract the conditional expression in a
local variable of type Object.
Comment 1 Philipe Mulet CLA 2005-02-08 17:25:00 EST
As soon as both operands are numeric using unboxing, conditional operator is
unboxing both operands. So bool ? Integer : Character ==> bool ? int : char.
We were incorrectly letting it use the reference type scenario instead.

Added AutoboxingTest#test095-096
Fixed
Comment 2 Jerome Lanneluc CLA 2005-02-15 07:29:21 EST
Verified in I20050214