Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array binding pattern with only OmittedExpressions does not check RHS of for-of loop #48630

Closed
Fireboltofdeath opened this issue Apr 10, 2022 · 7 comments Β· Fixed by #49008
Closed

Array binding pattern with only OmittedExpressions does not check RHS of for-of loop #48630

Fireboltofdeath opened this issue Apr 10, 2022 · 7 comments Β· Fixed by #49008
Labels
Bug Good First Issue Help Wanted
Milestone

Comments

@Fireboltofdeath
Copy link

@Fireboltofdeath Fireboltofdeath commented Apr 10, 2022

Bug Report

πŸ”Ž Search Terms

array binding patterns for-of loop omittedexpression binding elements

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// doesn't error
for (const [,] of doesntExist() /= 2) {

}

// does error
for (const [_,,,] of doesntExist() /= 2) {

}

πŸ™ Actual behavior

The right hand side of the for-of loop is not checked at all.

This appears to be because OmittedExpression is not actually a BindingElement and the right hand side's type is only checked whenever encountering a BindingElement in checkVariableLikeDeclaration or when there are no elements in the pattern.

πŸ™‚ Expected behavior

The right hand side of the for-of loop to be checked.

@RyanCavanaugh RyanCavanaugh added Bug Help Wanted labels Apr 11, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Apr 11, 2022
@RyanCavanaugh RyanCavanaugh added the Good First Issue label Apr 11, 2022
@wannieman98
Copy link

@wannieman98 wannieman98 commented Apr 14, 2022

Can I give this issue a try?

@Fireboltofdeath
Copy link
Author

@Fireboltofdeath Fireboltofdeath commented Apr 15, 2022

Can I give this issue a try?

Yes, feel free.

@wannieman98
Copy link

@wannieman98 wannieman98 commented Apr 15, 2022

Can I get some help on where I should begin looking to tackle this issue? Thanks!

@Fireboltofdeath
Copy link
Author

@Fireboltofdeath Fireboltofdeath commented Apr 15, 2022

You should take a look in checkVariableLikeDeclaration which is where the right side of the for-of loop gets checked, when encountering a binding element or pattern.

@wannieman98
Copy link

@wannieman98 wannieman98 commented Apr 16, 2022

Hi, sorry for another question, but I had been trying to fix the problem but I am not sure whether the [,] counts as a variable declaration or array literal. Could I get a clarification on that?

@bentongxyz
Copy link
Contributor

@bentongxyz bentongxyz commented Apr 24, 2022

Hi there, if this is not being actively worked on right now, may I give this a try?
Thanks!

@bentongxyz
Copy link
Contributor

@bentongxyz bentongxyz commented May 7, 2022

Hi @RyanCavanaugh @Fireboltofdeath, I made a PR for this issue, please check at your latest convenience!

Much thanks.

andrewbranch added a commit that referenced this issue May 31, 2022
…not check RHS of for-of loop (#49008)

* fix RHS of for..of loop not evaluated when LHS is array binding element with OmittedExpression

* expand widened type check

* add more test cases

* update code with suggestions

* Make test target es2015

Co-authored-by: Andrew Branch <andrew@wheream.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Good First Issue Help Wanted
Projects
None yet
4 participants