Repository navigation
Iterables and generators: arrays and strings as Iterable<T>, typed generator yields (TSLANG 153) - #973
Merged
Conversation
…Generator<T>: next) is wanted: a generator over its elements, made from source once a module Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… yields T: next() is declared { value: T; done: boolean }; a returned value of another TReturn is an error, not a silent cast
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…under -mm=own, not async) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…enerator as its own iterator, the TReturn error Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…resolved its this through an outer alias); TSLANG 153 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the compiler side of the default library's iteration types (ASDAlexander77/TypeScriptCompilerDefaultLib#113). There,
Iterable<T>,Generator<T, TReturn, TNext>and the rest are objects withnext.What changed
sum([1.5, 2])where the parameter isv: Iterable<number>, orcat("abc")where it isv: Iterable<string>.__array_values<T>and__string_values<T>) are generated from source once per module, and their element type is the interface's. So ans32[]given to anIterable<number>is converted first.-mm=ownthe generator borrows the array.Generator<T>(orIterator<T>,Iterable<T>,IterableIterator<T>) now yieldsT: itsnext()is declared{ value: T; done: boolean }, soyield 1gives anumber.s32), which failed with "can't assign '() => {value:s32, ...}' to '() => {value:number, ...}'".Generator<T, TReturn>whosereturngives a value of another type is now a compile error at thereturn. Before,return "end"in aGenerator<number, string>was silently converted to a number and read as 0.Verification
00iterables.tsand00generator_typed_yield.ts(compile, JIT and rc), and the diagnostic testgenerator_return_of_other_type.ts.binaryArithmeticControlFlowGraphNotTooLargetiming out; it also timed out in the batch 23 baseline.Still open (in TSLANG 153)
next(value)/TNext,return(),throw(): I tried thenext(value?: TNext)parameter; it works when the generator is cast to an interface that declares that parameter. Butnext()is then also cast to interfaces that declarenext: () => ...(a program's own, or the library'sIterable). An object's method with a different number of parameters has no adapter in an interface vtable; classes have one. So that adapter comes first.[Symbol.iterator]on a generator: I tried it and backed it out. The built-inmap/filteron iterators then resolved itsthisthrough an outer alias, and under own a method returningthisis refused.-mm=own: a generator typed as any interface other than the library's instantiatedIterator<T>fails at itsfor...ofwith "a value takes a second reference". This was already the case before this change, and the same applies to an array passed as anIterable<T>.🤖 Generated with Claude Code