Skip to content

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

Open

Description

🔎 Search Terms

getAsyncFromSyncIterationTypes, yield thenable, TS1321 crash, yield* Debug Failure

🕗 Version & Regression Information

Reproduces with the JavaScript checker in typescript@6.0.3 and the native checker in typescript@7.1.0-beta and typescript@7.1.0-dev.20261111.1, on Linux x64 using Node.js 24.20.0.

Also reproduces in an unmodified local build of current main, commit ad24728023c52ef6a92a278046cdb69621048365 (7.1.0-dev), built with node node_modules/hereby/bin/hereby.js build.

The first affected version has not been identified. I reviewed the FAQ and found no entry covering this crash.

💻 Code

Save as repro.ts:

declare const thenable: { then(onfulfilled: number): void };
async function* gen() {
  yield* [thenable];
}
npm install typescript@7.1.0-dev.20261111.1
npx tsc --noEmit --strict --target esnext repro.ts

🙁 Actual behavior

The native checker panics while constructing a diagnostic:

panic: runtime error: invalid memory address or nil pointer dereference
.../internal/diagnostics.(*Message).Code
.../internal/checker.NewDiagnosticChainForNode
.../internal/checker.(*Checker).getAwaitedTypeNoAliasEx
.../internal/checker.(*Checker).getAwaitedTypeEx
.../internal/checker.(*Checker).getAsyncFromSyncIterationTypes

The local native build reproduces in both default mode and with --singleThreaded.

The JavaScript checker in 6.0.3 also crashes:

Error: Debug Failure.
    at getAwaitedTypeNoAlias
    at getAwaitedType
    at getAsyncFromSyncIterationTypes
    at getIterationTypesOfIterableWorker

🙂 Expected behavior

Report an ordinary diagnostic for the invalid thenable and complete checking without an internal error.

For comparison, replacing yield* [thenable] with yield thenable reports TS1321 without crashing on all three versions:

Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.

Replacing the operand with yield* [1] succeeds.

Additional information about the issue

getAsyncFromSyncIterationTypes calls getAwaitedTypeEx with a non-nil error node but a nil diagnostic message. The invalid-thenable error path later attempts to construct a diagnostic using that message. In the JavaScript implementation the equivalent path asserts that the message is defined.

Source inspected at commit ad24728023c52ef6a92a278046cdb69621048365:
https://github.com/microsoft/TypeScript/blob/ad24728023c52ef6a92a278046cdb69621048365/tsc/internal/checker/checker.go#L6656-L6670

Related reports:

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions