Skip to content

next(value) of a Generator<T, TReturn, TNext>; an object method of another arity fills an interface member - #974

Merged
ASDAlexander77 merged 2 commits into
mainfrom
generator-next-value
Nov 21, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
generator-next-value

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Follow-up to #973 (TSLANG 153).

An object method of another arity fills an interface member. An object-literal method given as an interface's function member that takes fewer parameters (next() for next: (value?: number) => R, the rest ignored as JavaScript does), or more optional ones (next(v?) for next: () => R), was refused: "can't assign '() => ...' to '(p1: number | undefined) => ...': it takes 0 argument(s), 2 expected". The vtable slot now holds a thunk that gives the method as many arguments as it takes (isArityAdaptableObjectMethod, generateSynthMethodToCallField), the same way as for a field holding a closure.

next(value) of a Generator<T, TReturn, TNext>. The generator's next() takes value?: TNext, and the yield it resumes evaluates to that value as a TNext. When next() is given no value (the first call, a for...of), the yield gives TNext's default. It used to give undefined. A generator whose next() takes no value can still be used as such a Generator, and the other way round.

The default library's Generator should declare next: (value?: TNext) => ... once a compiler with this change is released; a released compiler without it can't treat a plain generator as one. With that declaration patched in locally, the library's tests/iteration_types.ts passes under gc, rc and own.

Still open (TSLANG 153): return()/throw(); under -mm=own, sending an object through next() (next() keeps the object it is given).

Tests: 00object_method_arity.ts, 00generator_next_value.ts (compile, JIT, rc, own). Full ctest locally: 8776 run, 0 failed.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits November 21, 2026 14:06
…other arity fills an interface member

A generator typed Generator<T, TReturn, TNext> gets next(value?: TNext), and the `yield` it resumes evaluates to
the value (TNext's default when none is given). An object-literal method taking fewer parameters than the
interface's member, or more optional ones, is called through a thunk giving it as many arguments as it takes,
so a generator whose next() takes no value is a Generator whose next takes one, and the other way round.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at stays open

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 125a457 into main Nov 21, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the generator-next-value branch November 21, 2026 15:03
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