Export to GitHub

google-web-toolkit - issue #6373

Compiler ignores Javascript unary plus operator


Posted on May 18, 2011 by Helpful Rabbit

Found in GWT Release (e.g. 1.5.3, 1.6 RC):

GWT 2.3.0

Encountered on OS / Browser (e.g. WinXP, IE6-7, FF3):

Windows 7, all browsers

Detailed description (please be as specific as possible):

The GWT compiler misinterprets the Javascript unary plus operator, which can be used to convert its operand to a number. However, it seems that the compiler ignores the operator.

This is similar to description of the fixed GWT issue 3942. Possibly that issue should be reopened.

Shortest code snippet which demonstrates issue (please indicate where actual result differs from expected result):

native double toNumber(boolean value) /-{ return +value; }-/;

native double toNumber(String value) /-{ return +value; }-/;

void issue() { // Throws HostedModeException in development mode // Alerts "true" instead of "1" in production mode Window.alert("" + (toNumber(true)));

// Throws HostedModeException in development mode
// Alerts "1234" instead of "235" in production mode
Window.alert("" + (1 + toNumber("234")));

}

Workaround if you have one:

Use Javascript Number as function (not as constructor):

native double toNumber(String value) /-{ return Number(value); }-/;

Or use double negation:

native double toNumber(String value) /-{ return -(-value); }-/;

Links to relevant GWT Developer Forum posts:

Similar fixed GWT issue 3942: http://code.google.com/p/google-web-toolkit/issues/detail?can=1&q=3942&colspec=ID%20Type%20Status%20Owner%20Milestone%20Summary%20Stars&id=3942

Comment #1

Posted on May 27, 2013 by Massive Cat

Look legit, since we treat +something other in Java

Comment #2

Posted on May 28, 2013 by Grumpy Cat

Interesting this was fixed (4b10f70918dc565a8f7a755b555904d9cb029bd0) and rolled back (28f568d309fcc31f4fa2a29d8a36be308053db23).

I'll look at this.

Comment #3

Posted on May 28, 2013 by Grumpy Cat

(No comment was entered for this change.)

Comment #4

Posted on May 30, 2013 by Grumpy Dog

(No comment was entered for this change.)

Comment #5

Posted on Aug 8, 2013 by Grumpy Cat

(No comment was entered for this change.)

Comment #6

Posted on Aug 8, 2013 by Grumpy Cat

(No comment was entered for this change.)

Comment #7

Posted on Feb 5, 2014 by Happy Elephant

Changed status because 2.6 is released.

Status: Fixed

Labels:
Milestone-2_6 Type-Defect