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

Aperta
#3,632 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp, typescript
Ambito
compilers

Direzione di ricerca

Start from TryGetAsyncIterator in the interpreter, where the built-in async generator fast path runs before the Symbol.asyncIterator lookup on the object. Run the repro with --no-tsconfig --noLib and confirm it prints 1. Done when the override is honored and the output is 7, matching Node and the compiled assembly.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C#
Stelle
156
Fork
4
Merge medio
16h 37m
PR unite (30g)
41

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nickna/SharpTS

Tutte le issue di nickna/SharpTS

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.