From 11efedb1e3f1aa22751f8aa61842015c65dfc0d8 Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Sun, 22 Nov 2026 00:24:51 +0000 Subject: [PATCH] Generator: next() takes no value again - given to an Iterable as it is, (value?) => called as () => was another signature (wasm: iteration_types.ts trapped) Co-Authored-By: Claude Opus 5.5 --- src/types/lib.types.d.ts | 10 ++++++---- tests/generator_next_return.ts | 17 +---------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/types/lib.types.d.ts b/src/types/lib.types.d.ts index 7123901..5bf5f2d 100644 --- a/src/types/lib.types.d.ts +++ b/src/types/lib.types.d.ts @@ -14,9 +14,7 @@ interface ClassIterator { // an object with next(), and for...of takes any object with next(), so here an Iterable is such an // object too (not one with [Symbol.iterator]): `function* g(): Generator`, and a generator // given to an Iterable or Iterator parameter, work, and so does an array or a string given to an -// Iterable. next(value) of a Generator is what the `yield` it resumes evaluates -// to; a generator whose next() takes no value is a Generator too. A returned value of a type other -// than T is an error. return(value) and throw(e) resume a paused generator finishing (its finally blocks +// Iterable. A returned value of a type other than T is an error. return(value) and throw(e) resume a paused generator finishing (its finally blocks // run) or throwing at its yield. IteratorResult is an alias, not an interface, so a generator's next() // matches it. type IteratorResult = IterateResult; @@ -30,7 +28,11 @@ interface IterableIterator { } interface Generator { - next: (value?: TNext) => IterateResult; + // next() takes no value here: a Generator is given to an Iterable as it is, so their next() must be one + // function type - `(value?: TNext) =>` called as an Iterable's `() =>` was a call of another signature (wasm's + // "function signature mismatch"; natively the yield read a value never given). Not declared here yet: + // next(value) (TSLANG 153). + next: () => IterateResult; // a generator declared to return a Generator has them (-mm=own: return() only for a T that owns nothing, a // number or a boolean); one declared otherwise, or not at all, is a Generator without them return?: (value: T) => IterateResult; diff --git a/tests/generator_next_return.ts b/tests/generator_next_return.ts index 63cb051..69693b9 100644 --- a/tests/generator_next_return.ts +++ b/tests/generator_next_return.ts @@ -1,17 +1,9 @@ -// Generator: next(value) is what the `yield` it resumes evaluates to, return(value) +// Generator: return(value) // finishes a paused generator (its finally blocks run), throw(e) throws at its yield. An // array given to an Iterable is iterated (under -mm=own its copy). let cleaned = 0; -function* running(): Generator { - let total: number = 0; - while (true) { - const v = yield total; - total += v; - } -} - function* guarded(): Generator { try { yield 1; @@ -46,13 +38,6 @@ function sum(values: Iterable) { } function main() { - const r = running(); - r.next(); - r.next(2); - r.next(3.5); - const t = r.next(4); - assert(t.value == 9.5 && !t.done, "next(value)"); - const g = guarded(); assert(g.next().value == 1, "first"); const f = g.return(7);