Skip to content

Add new experimental query MultipleArgumentsToSetConstructor.#5939

Merged
codeql-ci merged 1 commit into
github:mainfrom
max-schaefer:js/set-constructor-args
May 21, 2021
Merged

Add new experimental query MultipleArgumentsToSetConstructor.#5939
codeql-ci merged 1 commit into
github:mainfrom
max-schaefer:js/set-constructor-args

Conversation

@max-schaefer

Copy link
Copy Markdown
Contributor

As @johanrosenkilde and myself found out the hard way the other day, the Set constructor ignores all but its first argument, so new Set('a', 'b', 'c') gives you the singleton set { 'a' }. This is a cheap and cheerful query to spot cases like that. It's fairly precise in practice (see evaluation shared internally).

@max-schaefer max-schaefer requested a review from a team as a code owner May 21, 2021 09:00
@esbena

esbena commented May 21, 2021

Copy link
Copy Markdown
Contributor

LGTM.
This is a very specialized query - if this wasn't in experimental, we should generalize the name and check the provided externs signatures instead.

@max-schaefer

Copy link
Copy Markdown
Contributor Author

This is a very specialized query - if this wasn't in experimental, we should generalize the name and check the provided externs signatures instead.

Agreed, that's partly why I put it there.

To some extent this query should be subsumed by a type checker, except that we actually encountered this bug in TypeScript: while the TypeScript compiler will reject new Set(1, 2, 3) and new Set("a", "b", "c") because of a signature mismatch and even new Set(...[1, 2, 3]) because numbers aren't iterable, it will happily accept new Set(...["a", "b", "c"]) because strings are. (And TypeScript doesn't reason about array lengths, so it is fairly liberal about allowing ...xs arguments in calls.)

@codeql-ci codeql-ci merged commit 131c08e into github:main May 21, 2021

@datuplambik datuplambik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Samsudin88plambik@gmail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants