-
Notifications
You must be signed in to change notification settings - Fork 900
Closed
Labels
Description
The following cannot be evaluated and leads to an exception with 1.7R3 and later
var a = [1, 2]; var b = 0; [a[b+1], a[b]] = [a[b], a[b+1]]; a[0]
Exception:
java.lang.IllegalStateException: FAILED ASSERTION: unexpected token: ADD
at org.mozilla.javascript.Kit.codeBug(Kit.java:366)
at org.mozilla.javascript.IRFactory.decompile(IRFactory.java:2498)
at org.mozilla.javascript.IRFactory.decompileElementGet(IRFactory.java:2549)
at org.mozilla.javascript.IRFactory.decompile(IRFactory.java:2492)
at org.mozilla.javascript.IRFactory.decompileArrayLiteral(IRFactory.java:2509)
at org.mozilla.javascript.IRFactory.decompile(IRFactory.java:2469)
at org.mozilla.javascript.IRFactory.transformAssignment(IRFactory.java:441)
at org.mozilla.javascript.IRFactory.transform(IRFactory.java:222)
at org.mozilla.javascript.IRFactory.transformExprStmt(IRFactory.java:559)
at org.mozilla.javascript.IRFactory.transform(IRFactory.java:219)
at org.mozilla.javascript.IRFactory.transformScript(IRFactory.java:1133)
at org.mozilla.javascript.IRFactory.transform(IRFactory.java:201)
at org.mozilla.javascript.IRFactory.transformTree(IRFactory.java:121)
at org.mozilla.javascript.Context.parse(Context.java:2484)
at org.mozilla.javascript.Context.compileImpl(Context.java:2401)
at org.mozilla.javascript.Context.compileString(Context.java:1369)
at org.mozilla.javascript.Context.compileString(Context.java:1357)
at org.mozilla.javascript.Context.evaluateString(Context.java:1135)
at de.ndn.labs.RhinoBugTest.main(RhinoBugTest.java:16)
But it is evaluated with 1.7R2 (to "2"). I really don't understand why this works in a very old version and fails in all newer versions.
The only thing that works is removing the "+" in the array access:
var a = [1, 2]; var b = 0; var c = 1; [a[c], a[b]] = [a[b], a[c]]; a[0]
Minimal Java example here (and attached)
https://github.com/ndeuma/rhino-bugtest