Closed
Bug 39309
Opened 25 years ago
Closed 25 years ago
concatenating string and number doesn't work compiled.
Categories
(Rhino Graveyard :: Compiler, defect, P3)
Tracking
(Not tracked)
VERIFIED
FIXED
1.5R5
People
(Reporter: vajda, Assigned: norrisboyd)
Details
Attachments
(1 file)
1.17 KB,
patch
|
Details | Diff | Splinter Review |
Given the code:
{
var i = 0;
while (i++ < 5) {
var text = inputText + i;
... do stuff ...
}
Interpreted the above code works, that is text is the inputText followed by a
number.
Compiled (with max optimization level) text becomes NaN.
The interpreted behaviour is the correct one according to the javascript book
(O'Reilly rhino).
Since this is a discrepancy between interpreted and compiled script it is major.
The current workaround is to call i.toString() before concatenating.
This happens on the latest rhinoTip, js.jar is dated 4/25 and is 331802 bytes
long.
Assignee | ||
Updated•25 years ago
|
Status: NEW → ASSIGNED
Assignee | ||
Comment 2•25 years ago
|
||
I tried the following:
[rhino] cat test.js
var inputText = "hi";
var i = 0;
while (i++ < 5) {
var text = inputText + i;
print(text);
}
[rhino] java org.mozilla.javascript.tools.shell.Main -opt 9 test.js
hi1
hi2
hi3
hi4
hi5
Can you give me more information on the code that fails?
Assignee | ||
Comment 3•25 years ago
|
||
Wait....
I found this from a mail:
==================================================
I just posted a compiler bug on bugzilla (#39309).
It has to do with concatenating a string and a number.
Interpreted concatenation works. Compiled it produces 'NaN'.
Andi..
for example:
function addSnackItems(textProp, imageProp, len, centerText,
centerImages)
{
var fragment = new Fragment(inputNode.doc);
var i = 0;
while (++i <= len)
{
var iString = i.toString();
var name = textProp + iString;
var imgname = imageProp + iString;
if (addSnackTextItem(fragment, name, null, 0, 0, centerText))
addSnackImageItem(fragment, imgname, centerImages);
}
return fragment;
}
If you take the .toString() calls away, concatenation name becomes
'NaN'.
Assignee | ||
Comment 4•25 years ago
|
||
Okay: this case generates the error:
function addSnackItems(textProp, len) {
var i = 0;
while (++i <= len) {
var name = textProp + i;
print(name);
}
}
addSnackItems("text", 1);
This will print out "NaN" rather than "text1".
I've tracked down the problem this far: It only occurs with -opt 9 and is caused
by Optimizer.findSinglyTypedVars calling setIsNumber for the "name" variable.
Could you take a look at it, Roger, since it's your code?
Assignee: nboyd → rogerl
Status: ASSIGNED → NEW
Assignee | ||
Comment 6•25 years ago
|
||
Comment 7•25 years ago
|
||
Fix checked in + addition to handle case of var being used before def'd.
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
Comment 8•21 years ago
|
||
Testcase added to JS testsuite:
mozilla/js/tests/js1_5/Regress/regress-39309.js
Marking Verified FIXED. The testcase passes in the Rhino shell
on WinNT4.0 with optimization levels set to -1, 0, or 9.
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•