Skip to content

Interpreter for-await ignores an async generator Symbol.asyncIterator override #3632

Closed

Description

@nickna
async function* source() { yield 1; }
const gen: any = source();
gen[Symbol.asyncIterator] = function () {
    let done = false;
    return {
        next() {
            if (done) return { done };
            done = true;
            return { done: false, value: 7 };
        }
    };
};
async function main() { for await (const value of gen) console.log(value); }
main();

Run with --no-tsconfig --noLib. The SharpTS interpreter prints 1. Node (with the type annotation removed) and a saved SharpTS assembly built with --compile --verify print 7.

for await should call the generator object's own Symbol.asyncIterator override. The interpreter's TryGetAsyncIterator takes the built-in async generator fast path before looking up the symbol. Found while working on #3616 and #3618.

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