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)

x86
Windows NT

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: vajda, Assigned: norrisboyd)

Details

Attachments

(1 file)

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.
Status: NEW → ASSIGNED
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?
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'.
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
Reassign back to me.
Assignee: rogerl → nboyd
Attached patch proposed patchSplinter Review
Fix checked in + addition to handle case of var being used before def'd.
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
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
Trageting as resolved against 1.5R5
Target Milestone: --- → 1.5R5
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: