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

incorrect diagnostic: using a '.' after a '?.' might fail #1192

Closed
vegerot opened this issue Jan 23, 2024 · 3 comments
Closed

incorrect diagnostic: using a '.' after a '?.' might fail #1192

vegerot opened this issue Jan 23, 2024 · 3 comments
Assignees
Milestone

Comments

@vegerot
Copy link
Contributor

vegerot commented Jan 23, 2024

minimal example:

undefined?.a.b

quick-lint reports: using a '.' after a '?.' might fail, since '?.' might return 'undefined'., however this is not true.

Running the above code shows that optional chaining short-circuits the entire property access expression to undefined, not just the first property access.

❯ deno
Deno 1.39.4
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> undefined?.a.b.c.d
undefined

idk if there's a "correct" version of this diagnostic, or if we should just delete the whole thing

@vegerot
Copy link
Contributor Author

vegerot commented Jan 23, 2024

A better version of this diagnostic would be to check for non-null assertions, which are incorrect.

undefined?.a!.b

@strager strager added this to the 3.2 milestone Jan 25, 2024
strager referenced this issue in dlarocque/quick-lint-js Jan 25, 2024
This closes quick-lint#1128 -- it warns the user about using a dot After an optional chain. This cover optional chain with function call as well as optional chain with index expressions
@strager strager self-assigned this Jan 25, 2024
@strager
Copy link
Collaborator

strager commented Jan 25, 2024

Fixed in Git commit 434d085. I will ship the fix in version 3.2.0.

@strager
Copy link
Collaborator

strager commented Mar 4, 2024

Fix released in version 3.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants