|let| with destructuring compiled incorrectly (decompiled too in for-in head)

RESOLVED WORKSFORME

Status

()

RESOLVED WORKSFORME
11 years ago
7 years ago

People

(Reporter: jruderman, Unassigned)

Tracking

(Blocks: 1 bug, {testcase})

Trunk
x86
Mac OS X
testcase
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

11 years ago
A variable declared in "let" is normally not bound within the initial-value expression, but if the declaration uses destructuring, it is.

js> x = 3; let (x = x) { print(x) }       
3
js> x = 3; let ([x] = [x]) { print(x) }   
undefined

I'm guessing this is wrong; I'd expect to see "3" in both cases.

This leads to changes in behavior through decompilation when for..let hoisting comes in:

js> f = function() { x = 1; for (let [x] = print(x) in []) { } }             
function () {
    x = 1;
    print(x);
    for (let [x] in []) {
    }
}
js> f()
undefined
js> eval(uneval(f))()
1
Quote:

"Note: In contrast with normal assignment expressions, the locations updated by destructuring assignment are not computed before the value that is to be stored. Destructuring assignment is simple syntactic sugar for a common compute-and-destructure pattern, and true to this pattern it computes the value prior to computing the locations. (See discussion below for more detail.)"

from

https://intranet.mozilla.org/ECMA/wiki/doku.php?id=proposals:destructuring_assignment

This works as designed and is independent of let vs. var.

/be
Status: NEW → RESOLVED
Last Resolved: 11 years ago
Resolution: --- → INVALID
Sorry, missed the decompiler bug.

/be
Status: RESOLVED → REOPENED
Resolution: INVALID → ---
Summary: Variable declared using |let| with destructuring is incorrectly bound within the initial-value expression → for-in with |let| and destructuring decompiled incorrectly
I'm a complete idjit today (need more coffee). Jesse's right, this is indeed a destructuring bug, and the hoisting comment points to a decompiler issue to fix or keep working while fixing the compilation bug.

Blake, you interested in this bug?

/be
Summary: for-in with |let| and destructuring decompiled incorrectly → |let| with destructuring compiled incorrectly (decompiled too in for-in head)
js> x = 3; let (x = x) { print(x) }
3
js> x = 3; let ([x] = [x]) { print(x) }
3
Status: REOPENED → RESOLVED
Last Resolved: 11 years ago7 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.