Skip to content

Port TypeScript#62676: Fix slow sync iteration types spoiling cached async iteration types#2728

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-slow-sync-iteration-types
Open

Port TypeScript#62676: Fix slow sync iteration types spoiling cached async iteration types#2728
Copilot wants to merge 2 commits intomainfrom
copilot/fix-slow-sync-iteration-types

Conversation

Copy link
Contributor

Copilot AI commented Feb 10, 2026

When a type implements both Iterable<T_Sync> and AsyncIterable<T_Async>, the sync slow resolution path could cache results before the async slow path ran, causing for await loops to incorrectly yield the sync type parameter instead of the async one.

type Stream<T_Sync, T_Async> = Iterable<T_Sync> & AsyncIterable<T_Async>;

async function loop(stream: Stream<A, B>) {
  for await (const b of stream) {} // b was incorrectly typed as A instead of B
}
  • Move getIterationTypesOfIterableSlow calls inside their respective fast-check blocks so async slow resolution always completes before sync slow resolution runs, preventing cache poisoning

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…hed value for async ones

Move getIterationTypesOfIterableSlow calls inside their respective
fast-check blocks to prevent sync slow iteration types from being
resolved and cached before async slow types, which was causing
incorrect async iteration types.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with slow sync iteration types Port TypeScript#62676: Fix slow sync iteration types spoiling cached async iteration types Feb 10, 2026
Copilot AI requested a review from jakebailey February 10, 2026 22:12
@jakebailey
Copy link
Member

Hm, this does nothing. Maybe we avoid the problem entirely now?

@jakebailey
Copy link
Member

microsoft/TypeScript#62676

Probably worth pulling, just because this probably is an ordering thing we now just so happen to avoid in this case, but not others

@jakebailey jakebailey marked this pull request as ready for review February 13, 2026 00:50
Copilot AI review requested due to automatic review settings February 13, 2026 00:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Ports TypeScript#62676 to the Go checker to ensure for await...of prefers AsyncIterable iteration types over sync fallbacks, avoiding incorrect cached results when a type supports both sync and async iteration.

Changes:

  • Reorders getIterationTypesOfIterableWorker resolution so async slow-path resolution completes before any sync-path fallback.
  • Shares a single diags slice across the async/sync slow paths for related diagnostic info.

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

Successfully merging this pull request may close these issues.

2 participants