New issue
Advanced search Search tips

Issue 599850 link

Starred by 3 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Feature

Blocking:
issue v8:6513



Sign in to add a comment

Array destructuring in function parameters results in poor error messages

Reported by m.go...@gmail.com, Apr 1 2016

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36

Steps to reproduce the problem:
1. Enter `var [a] = 2` in the console
2. 
3. 

What is the expected behavior?
You should see a message describing a failed destructuring attempt that would say where exactly the problem lies.

What went wrong?
The error is "undefined is not a function". There's no function involved here so this completely doesn't relate to the actual issue. This is most likely V8 looking for the iterator .next() method & not finding it but that shouldn't surface to the user in this way.

Imagine this in a larger piece of code and you looking for a function that doesn't exist where the problem lies in a different place.

Did this work before? No 

Chrome version: 51.0.2696.0   Channel: canary
OS Version: OS X 10.11.4
Flash Version: Shockwave Flash 21.0 r0

Firefox displays "TypeError: 2 is not iterable".

Safari displays:
"TypeError: [a] is not a function. (In '[a]', '[a]' is undefined)"
In a larger assignment, like:
var [b, [a]] = [2, 3]
you'll see:
TypeError: [a] is not a function. (In '[a]', '[a]' is undefined)
so the place where the problem lies is clear.
 
Components: -Blink Blink>JavaScript
Cc: adamk@chromium.org
Components: -Blink>JavaScript Blink>JavaScript>Language
Labels: -Type-Bug -OS-Mac OS-All Type-Feature
Status: Available (was: Unconfirmed)
Still 'broken' in Chrome 57 on WIN.

If there is a function involved, it's even more confusing, because the function isn't relevant.

xx = ([a, b]) => console.log(a, b);
xx({x: 4});

Error in Chrome: Uncaught TypeError: undefined is not a function

Error in Firefox: TypeError: (destructured parameter) is not iterable

Comment 4 by adamk@chromium.org, Aug 8 2017

Blocking: v8:6513
Owner: gsat...@chromium.org
Status: Assigned (was: Available)
The original report is now fixed, but the report in #c3 looks to still need work (destructuring params don't seem to have a good error message).

Comment 5 by adamk@chromium.org, Aug 8 2017

Summary: Array destructuring in function parameters results in poor error messages (was: Unintuitive error on mismatched destructuring)

Sign in to add a comment