Bug 122987 - [1.5][compiler] Boxing conversion should be performed in conditional expression
Summary: [1.5][compiler] Boxing conversion should be performed in conditional expression
Status: VERIFIED FIXED
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 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-06 19:17 EST by Chris Smith CLA
Modified: 2006-02-15 07:53 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 Chris Smith CLA 2006-01-06 19:17:39 EST
Eclipse 3.2M3

public class Test
{
    public static void main(String[] args)
    {
        Object obj = true ? true : 17.3;
    }
}

Eclipse says:

Incompatible conditional operand types Boolean and double

JLS says:

Otherwise, the second and third operands are of types S1 and S2 respectively.  Let T1 be the type that results from applying boxing conversion to S1, and let T2 be the type that results from applying boxing conversion to S2.  The type of the conditional expression is the result of applying capture conversion to lub(T1, T2).

As I understand it:

S1 = boolean, S2 = double
T1 = Boolean, T2 = Double
lub(T1, T2) = something assignment compatible with Object
capture applied to lub(T1, T2) = lub(T1, T2)

Therefore, the expression is valid and should yield Boolean.TRUE.  Eclipse seems to have applied boxing conversion to the second argument, but not to the third argument, and thus failed.

Oddly enough:

    Object obj = true ? true : Double.valueOf(17.3);

Eclipse gives the same error.  It converts true to type Boolean by boxing conversion, AND Double.valueOf(17.3) to double by unboxing conversion, and THEN gets stuck.
Comment 1 Philipe Mulet CLA 2006-02-02 13:05:04 EST
Good find. Indeed the compiler logic is wrong. It must promote both operands in this situation (bogus 'else' in between to IFs).

Added AutoboxingTest#test117
Comment 2 Philipe Mulet CLA 2006-02-02 13:06:06 EST
should backport to 3.1.x
Comment 3 Philipe Mulet CLA 2006-02-02 17:55:06 EST
Fixed in 3.2 and 3.1.x streams.
Comment 4 Jerome Lanneluc CLA 2006-02-15 07:53:06 EST
Verified for 3.2 M5 using build I20060215-0010