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

Code path analysis for (a && b) ?? c #13614

Closed
mdjermanovic opened this issue Aug 25, 2020 · 5 comments · Fixed by #17618
Closed

Code path analysis for (a && b) ?? c #13614

mdjermanovic opened this issue Aug 25, 2020 · 5 comments · Fixed by #17618
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features

Comments

@mdjermanovic
Copy link
Member

mdjermanovic commented Aug 25, 2020

Tell us about your environment

  • ESLint Version: v7.7.0
  • Node Version: v12.14.0
  • npm Version: 6.13.4

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?

default

Please show your full configuration:

Configuration
module.exports = {
  parserOptions: {
    ecmaVersion: 2020
  }
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

(a && b) ?? c;

The rest of the bug report template isn't quite suitable for this issue.

Code path analysis gives the following:

DOT
digraph {
node[shape=box,style="rounded,filled",fillcolor=white];
initial[label="",shape=circle,style=filled,fillcolor=black,width=0.25,height=0.25];
final[label="",shape=doublecircle,style=filled,fillcolor=black,width=0.25,height=0.25];
s1_1[label="Program:enter\nExpressionStatement:enter\nLogicalExpression:enter\nLogicalExpression:enter\nIdentifier (a)"];
s1_2[label="Identifier (b)\nLogicalExpression:exit"];
s1_3[label="Identifier (c)"];
s1_4[label="LogicalExpression:exit\nExpressionStatement:exit\nProgram:exit"];
initial->s1_1->s1_2->s1_3->s1_4;
s1_1->s1_4;
s1_2->s1_4->final;
}
Image

image

This would be correct for (a || b) ?? c, but I think it isn't entirely correct for (a && b) ?? c since there should be a path from a to c that doesn't go through b:

(null && console.log("b")) ?? console.log("c"); // logs only "c"
@mdjermanovic mdjermanovic added bug ESLint is working incorrectly core Relates to ESLint's core APIs and features evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Aug 25, 2020
@btmills
Copy link
Member

btmills commented Aug 30, 2020

This is a similar issue to #13634. I believe we can fix both in semver-minor changes.

@eslint-deprecated eslint-deprecated bot added the auto closed The bot closed this issue label Sep 30, 2020
@eslint-deprecated
Copy link

Unfortunately, it looks like there wasn't enough interest from the team
or community to implement this change. While we wish we'd be able to
accommodate everyone's requests, we do need to prioritize. We've found
that issues failing to reach accepted status after 21 days tend to
never be accepted, and as such, we close those issues.
This doesn't mean the idea isn't interesting or useful, just that it's
not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

@btmills btmills self-assigned this Oct 1, 2020
@btmills btmills reopened this Oct 1, 2020
@btmills btmills removed the auto closed The bot closed this issue label Oct 1, 2020
@aladdin-add
Copy link
Member

friendly ping @mdjermanovic is this still an issue we want to address?

@nzakas nzakas added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Aug 14, 2023
@nzakas
Copy link
Member

nzakas commented Aug 14, 2023

Yes, we should fix this.

@nzakas nzakas assigned nzakas and unassigned btmills Aug 15, 2023
@nzakas
Copy link
Member

nzakas commented Aug 15, 2023

Working on this.

fasttime pushed a commit that referenced this issue Oct 4, 2023
* fix: Ensure correct code path for && followed by ??

fixes #13614

* Remove .only

* Update lib/linter/code-path-analysis/code-path-state.js

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Update tests/lib/linter/code-path-analysis/code-path-analyzer.js

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Update variable names in comments

---------

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Apr 2, 2024
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants