Last Comment Bug 388442 - |let| with destructuring compiled incorrectly (decompiled too in for-in head)
: |let| with destructuring compiled incorrectly (decompiled too in for-in head)
Status: RESOLVED WORKSFORME
: testcase
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: x86 macOS
-- normal (vote)
: ---
Assigned To: general
:
: Steven DeTar [:sdetar]
Mentors:
Depends on:
Blocks: 349611
  Show dependency treegraph
 
Reported: 2007-07-17 11:32 PDT by Jesse Ruderman
Modified: 2011-11-16 19:27 PST (History)
4 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description User image Jesse Ruderman 2007-07-17 11:32:14 PDT
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
Comment 1 User image Brendan Eich [:brendan] 2007-07-17 11:44:15 PDT
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
Comment 2 User image Brendan Eich [:brendan] 2007-07-17 11:45:11 PDT
Public export of that wiki page:

http://developer.mozilla.org/es4/proposals/destructuring_assignment.html

/be
Comment 3 User image Brendan Eich [:brendan] 2007-07-17 11:49:09 PDT
Sorry, missed the decompiler bug.

/be
Comment 4 User image Brendan Eich [:brendan] 2007-07-17 11:53:39 PDT
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
Comment 5 User image Ryan VanderMeulen [:RyanVM] 2011-11-16 19:27:31 PST
js> x = 3; let (x = x) { print(x) }
3
js> x = 3; let ([x] = [x]) { print(x) }
3

Note You need to log in before you can comment on or make changes to this bug.