Skip to content

Fix checker crash when sync iteration awaits an invalid thenable - #65459

Open
Josué Barros (joshbarros) wants to merge 2 commits into
microsoft:mainfrom
joshbarros:fix/65452-yield-star-thenable
Open

Josué Barros (joshbarros) wants to merge 2 commits into
microsoft:mainfrom
joshbarros:fix/65452-yield-star-thenable

Conversation

@joshbarros

Copy link
Copy Markdown

Fixes #65452

getAsyncFromSyncIterationTypes passed a nil diagnostic into getAwaitedTypeEx. When a sync iterable's yield or return value is a thenable that is not a promise, the checker tried to build that diagnostic and crashed. The native compiler panics in Message.Code. The JavaScript checker hits Debug.assertIsDefined on the same path.

The diagnostic now names the construct that is waiting:

  • yield* of a sync iterable reports TS1322
  • for await reports TS1320
  • a direct yield still reports TS1321

yield* [1] and yield* [Promise.resolve(1)] still type-check.

I ran go test ./internal/testrunner for yieldStarSyncIterableThenable, and the existing forAwait, yieldStar, crashInYieldStar, and asyncYieldStar compiler tests. I did not run the full hereby suite.

Drafted with assistance from Grok. I reviewed the diff and ran those tests.

getAsyncFromSyncIterationTypes asked for an awaited type with a nil
diagnostic. Reporting an invalid thenable then dereferenced that
message. yield* reports TS1322 and for-await reports TS1320.
Copilot AI balanced review requested due to automatic review settings November 12, 2026 22:03
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 12, 2026
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the iteration-diagnostic changes and accompanying regression coverage.

No open issues 🎉

What changed in this PR

Fixes #65452 by making the native checker report diagnostics instead of crashing when asynchronous iteration encounters an invalid thenable from a synchronous iterable.

Changes:

  • Passes iteration context into awaited-type checking to select the appropriate diagnostic for yield* and for await.
  • Adds regression coverage for invalid thenables and valid delegated yields.
  • Records expected diagnostics, inferred types, symbols, and JavaScript output.
File Description
tsc/​testdata/​tests/​cases/​compiler/​yieldStarSyncIterableThenable.ts Adds invalid-thenable regressions and valid-yield checks.
tsc/​testdata/​baselines/​reference/​compiler/​yieldStarSyncIterableThenable.types Records expected inferred types.
tsc/​testdata/​baselines/​reference/​compiler/​yieldStarSyncIterableThenable.symbols Records expected symbol bindings.
tsc/​testdata/​baselines/​reference/​compiler/​yieldStarSyncIterableThenable.js Records expected JavaScript output.
tsc/​testdata/​baselines/​reference/​compiler/​yieldStarSyncIterableThenable.errors.txt Records TS1322, TS1321, and TS1320 diagnostics.
tsc/​internal/​checker/​checker.go Supplies context-specific diagnostics when awaiting iteration yield and return types.

Review effort: Balanced

…rationTypes

Review feedback: the comment was redundant or unclear. The diagnostic
choice is already visible from the surrounding code.
@joshbarros

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

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

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Checker crashes on yield* of a synchronous iterable containing an invalid thenable

3 participants