Skip to content

fix: model generator yield resumption paths in code path analysis#20665

Merged
fasttime merged 3 commits into
eslint:mainfrom
sethamus:generator-yield-code-paths
Apr 12, 2026
Merged

fix: model generator yield resumption paths in code path analysis#20665
fasttime merged 3 commits into
eslint:mainfrom
sethamus:generator-yield-code-paths

Conversation

@sethamus

Copy link
Copy Markdown
Contributor

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

This PR fixes code path analysis for suspended generator yield expressions.

Previously, code path analysis did not fully model the paths that can happen when a generator is resumed externally. In particular, it missed the return-like path created by Generator.prototype.return(), which caused a false positive in no-useless-assignment for generators inside try...finally.

This change teaches the analyzer to treat yield as a suspension point with multiple possible resumptions:

  • normal continuation on next()
  • throw-like exit on throw()
  • return-like exit on return()

Fixes #20583

Is there anything you'd like reviewers to focus on?

@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Mar 22, 2026
@netlify

netlify Bot commented Mar 22, 2026

Copy link
Copy Markdown

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit ea2602b
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/69d5f337afba14000864e1fb
😎 Deploy Preview https://deploy-preview-20665--docs-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@eslint-github-bot eslint-github-bot Bot added the bug ESLint is working incorrectly label Mar 22, 2026
@github-actions github-actions Bot added the core Relates to ESLint's core APIs and features label Mar 22, 2026
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

@github-actions github-actions Bot added the Stale label Apr 1, 2026
@sethamus sethamus marked this pull request as ready for review April 2, 2026 01:19
@sethamus sethamus requested a review from a team as a code owner April 2, 2026 01:19
@github-actions github-actions Bot removed the Stale label Apr 2, 2026
@DMartens

DMartens commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Changes LGTM; they are consistent with how the other nodes are handled.
Can you please add additional test cases for the no-useless-assignment rule:

  • yield outside try/catch
  • yield in try/catch without finally
  • yield in catch and finally block

@DMartens DMartens moved this from Needs Triage to Implementing in Triage Apr 3, 2026
@sethamus

sethamus commented Apr 8, 2026

Copy link
Copy Markdown
Contributor Author

Added the additional test cases.

@DMartens DMartens moved this from Implementing to Second Review Needed in Triage Apr 9, 2026
@fasttime

Copy link
Copy Markdown
Member

This change teaches the analyzer to treat yield as a suspension point with multiple possible resumptions:

* normal continuation on `next()`
* throw-like exit on `throw()`
* return-like exit on `return()`

I also think this is the correct approach.

@fasttime fasttime added the accepted There is consensus among the team that this change meets the criteria for inclusion label Apr 10, 2026

@fasttime fasttime left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@fasttime fasttime merged commit 14be92b into eslint:main Apr 12, 2026
40 checks passed
@github-project-automation github-project-automation Bot moved this from Second Review Needed to Complete in Triage Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly contributor pool core Relates to ESLint's core APIs and features

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Bug: no-useless-assignment false positive in generator functions

3 participants