Bug 23469 - switch (-1 * 0) { default: print("FAIL!"); case 0: }
Summary: switch (-1 * 0) { default: print("FAIL!"); case 0: }
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Gavin Barraclough
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-21 19:06 PST by Gavin Barraclough
Modified: 2009-01-28 14:52 PST (History)
1 user (show)

See Also:


Attachments
The patch (2.15 KB, patch)
2009-01-21 19:52 PST, Gavin Barraclough
no flags Details | Formatted Diff | Diff
Typo fix (2.15 KB, patch)
2009-01-21 20:01 PST, Gavin Barraclough
oliver: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gavin Barraclough 2009-01-21 19:06:25 PST
FAIL!
Comment 1 Mark Rowe (bdash) 2009-01-21 19:14:38 PST
Do we really add an exclamation point out of nowhere?
Comment 2 Gavin Barraclough 2009-01-21 19:52:53 PST
Created attachment 26920 [details]
The patch
Comment 3 Gavin Barraclough 2009-01-21 20:01:44 PST
Created attachment 26921 [details]
Typo fix
Comment 4 Oliver Hunt 2009-01-21 20:09:03 PST
Comment on attachment 26921 [details]
Typo fix

r=me, as long as there is a testcase
Comment 5 Gavin Barraclough 2009-01-21 20:28:49 PST
Sending        JavaScriptCore/ChangeLog
Sending        JavaScriptCore/interpreter/Interpreter.cpp
Sending        LayoutTests/ChangeLog
Sending        LayoutTests/fast/js/resources/switch-behaviour.js
Sending        LayoutTests/fast/js/switch-behaviour-expected.txt
Transmitting file data .....
Committed revision 40111.
Comment 6 Zoltan Herczeg 2009-01-27 01:20:07 PST
Hi,

the fix of this bug introduces a new bug. Consider the following code:

var a = 5.4

    switch(val) {
    case 1:
        return 10
    case 2:
        return 11
    case 3:
        return 12
    case 5:
        return 14
    case 6:
        return 15
    default:
        return 100
    }

The switch selects "case 5", because numberToInt32() converts 5.4 to 5, which is wrong in this case!

The right test should be something like this in case of scrutinee is a double value:
if ((double)((int)scrutinee) == scrutinee)
   ... ctiForValue((int)scrutinee)
Comment 7 Alexey Proskuryakov 2009-01-28 14:52:02 PST
Could you please file a new bug for this?