Skip to content

Async generator yield* skips custom Symbol.asyncIterator delegation in both engines #3616

Closed

Description

@nickna

A custom iterable with Symbol.asyncIterator can be consumed by for await, but SharpTS async generators fail to delegate to it with yield*. Run with --no-tsconfig --noLib and, for saved output, --compile --verify.

const iterable: any = {
    [Symbol.asyncIterator]() {
        return { next() { return Promise.resolve({ value: 1, done: false }); } };
    }
};
async function* inspect() {
    try {
        yield* iterable;
    } catch (error) {
        yield error.message;
    }
}
inspect().next().then(result => console.log(result.value, result.done));
  • Node prints 1 false.
  • The interpreter catches an error saying SharpTSObject is not iterable and prints that message followed by false.
  • Saved compiled output passes IL verification and prints undefined true.

Changing the iterator step to Promise.resolve(1) should instead enter the catch with a TypeError. Node does so, but the SharpTS outputs are unchanged. This is the delegation path, found while testing the for-await case in #3607.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions