Repository navigation
Generic type parameters shadow the enclosing one's; string-index interfaces are dictionaries; a generator is its own iterator - #981
Merged
Conversation
… string index signature is a dictionary; a generator is its own iterator
- A generic class, interface or type alias instantiated inside a generic function with a type parameter of
the same name as one of its own (`Box<S>` in `f<T, S>`, Box's parameter named T) took the function's:
`f(Box<number>, Box<string>)` inferred T = number | string and S = any, and read its second argument with
the wrong layout (a crash). The declaration's own parameters shadow the enclosing ones (shadowTypeParameters;
the prototype's self-alias only for a type-parameter argument, shadowTypeParameterAliases).
- `interface D<T> { [k: string]: T }` (a string index signature and nothing else) is the dictionary the same
type literal is; a class may still implement it. Without the default library's dictionary, as before.
- `g[Symbol.iterator]()` of a generator is g.
TSLANG 152, 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 PR fixes the remaining TSLANG 152 and 153 items that can be fixed in the compiler alone.
Box<S>inf<T, S>, where Box's parameter is named T). It took the function's T instead of its own.f(Box<number>, Box<string>)inferred T =number | stringand S =any, then read its second argument with the wrong layout and crashed.T → Tis looked up first.shadowTypeParameters). The alias is shadowed only when the argument is itself a type parameter (shadowTypeParameterAliases). A concrete instance made inside a generic prototype, such as the library'sTypedArray<u8>, keeps the old behaviour; shadowing it as well broke TypedArray, which the full sweep caught.interface D<T> { [k: string]: T }is a dictionary. An interface with a string index signature and nothing else (nothing extended, no decorator) is now the dictionary the same type literal is. A class may stillimplementsit. Without the default library's ObjectDictionary, it stays an interface, as before.g[Symbol.iterator]()returns g. It used to fail with "Can't resolve property 'iterator'".Tests
00generic_shadowed_type_param.tsand00generator_symbol_iterator.ts(compile, jit, rc, own)00object_dictionary.tsVerified
extendsthe dictionary interface; the failing line is a type error in TypeScript too. Recorded as open.Still open, in TSLANG_ISSUES
objectDictionaryAssignto take two type parameters.-mm=own: array growth on write,next(object), and iterator interfaces the program declares itself.🤖 Generated with Claude Code