Bug 155255 - [1.5][compiler] ternary conditional operator returns wrong type
Summary: [1.5][compiler] ternary conditional operator returns wrong type
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: All Linux
: P3 normal (vote)
Target Milestone: 3.2.2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-25 14:30 EDT by eclipse.19.jbag CLA
Modified: 2007-01-15 12:55 EST (History)
1 user (show)

See Also:


Attachments
Proposed patch (11.81 KB, patch)
2006-09-05 05:30 EDT, Philipe Mulet CLA
no flags Details | Diff
Better patch (17.70 KB, patch)
2006-09-05 09:06 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description eclipse.19.jbag CLA 2006-08-25 14:30:37 EDT
Another bug in the conditional operator, along the lines of Bug 117495 and Bug 122987:

Source code:

public class X {
    public static void main(String[] args) {
        Object x = true ? true : "";

        System.out.println("value " + x + " of class " + x.getClass().getCanonicalName());
    }
}


According to spec, x should have type Boolean, but instead it is assigned type String.

A similarly bizarre String conversion happens with other arguments when the alternate return values are of incompatible literal types.  For example:

    Object x = true ? 3.0f : false;
    Object x = true ? 2 : false;
    Object x = false ? 2 : false;

In all of these cases the resulting type of x is incorrectly java.lang.String.
Comment 1 Philipe Mulet CLA 2006-09-05 05:27:21 EDT
Problem comes from constant inlining missing the boxing conversion, and reverting by default to string conversion.
Comment 2 Philipe Mulet CLA 2006-09-05 05:30:06 EDT
Created attachment 49388 [details]
Proposed patch

Patch against 3.2maintenance stream.
Comment 3 Philipe Mulet CLA 2006-09-05 09:06:39 EDT
Created attachment 49396 [details]
Better patch

Patch for 3.2 maintenance
Comment 4 Philipe Mulet CLA 2006-09-05 09:30:10 EDT
Released for 3.3M2 (HEAD)
A little bit reluctant for 3.2.1, since the change is bigger than I would have preferred for pure maintenance. The patch passes all our tests.

Fixed
Comment 5 Philipe Mulet CLA 2006-09-18 05:21:10 EDT
reopening for addressing in 3.2.2 branch
Comment 6 Philipe Mulet CLA 2006-09-28 10:34:50 EDT
Released for 3.2.2
Comment 7 Frederic Fusier CLA 2006-10-29 07:31:48 EST
Verified for 3.3 M2 using build I20060922-0010.

Note that AutoBoxingTest#test0124() does not fail with 3.3 M1
=> not sure this is a variation of this bug...
Comment 8 Eric Jodet CLA 2007-01-15 06:33:10 EST
verified for 3.2.2 using build M20070112-1200