Skip to content

Resume a generator stored in an untyped local - #936

Open
phall1 wants to merge 1 commit into
vercel-labs:mainfrom
phall1:fix/generator-untyped-next
Open

phall1 wants to merge 1 commit into
vercel-labs:mainfrom
phall1:fix/generator-untyped-next

Conversation

@phall1

@phall1 phall1 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

iter.next() was lowered only when the checker's type of the receiver was a generator. Package JavaScript leaves that type as any, so a local that holds a generator became a runtime fence:

method calls like 'iter.next' is not supported yet (SC1090).

The local or global IR type is used when the checker type is not a generator. The identifier is pure, so the receiver is not evaluated twice.

export function collect(iterator) {
  const iter = iterator();
  const out = [];
  while (true) {
    const state = iter.next();
    if (state.done) return out;
    out.push(state.value);
  }
}
function* values(): Generator<number, void, unknown> {
  yield 1;
  yield 2;
  yield 3;
}
console.log(JSON.stringify(collect(() => values())));
// [1,2,3]

Differential test: packages/compiler/test/generator-iterator-next.test.ts. Native stdout, stderr, and exit match Node.

Before the change the native binary printed the SC1090 fence above and did not reach [1,2,3].

Effect's Stream.concat reaches this shape through Channel.fromIterator. The public harness is https://github.com/phall1/effect-scriptc-compat. This patch is the generator receiver check. It does not claim broader Effect parity.

A package function's checker type stays any, so iter.next() was a
runtime fence even when the local holds the call-site generator.
@vercel

vercel Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Someone is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant