Skip to content

Generic type parameters shadow the enclosing one's; string-index interfaces are dictionaries; a generator is its own iterator - #981

Merged
ASDAlexander77 merged 1 commit into
mainfrom
tslang-152-153-rest
Nov 21, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
tslang-152-153-rest

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

This PR fixes the remaining TSLANG 152 and 153 items that can be fixed in the compiler alone.

  • Generic type parameters shadow the enclosing function's. A generic class, interface or type alias was instantiated inside a generic function that has a type parameter of the same name as one of its own (Box<S> in f<T, S>, where Box's parameter is named T). It took the function's T instead of its own.
    • Effect: f(Box<number>, Box<string>) inferred T = number | string and S = any, then read its second argument with the wrong layout and crashed.
    • Cause: the instance's context starts from the function's. A type-parameter argument did not replace the T already there, and the prototype's alias T → T is looked up first.
    • Fix: the declaration's own parameters now shadow the enclosing ones (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's TypedArray<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 still implements it. Without the default library's ObjectDictionary, it stays an interface, as before.
  • A generator is its own iterator. g[Symbol.iterator]() returns g. It used to fail with "Can't resolve property 'iterator'".

Tests

  • 00generic_shadowed_type_param.ts and 00generator_symbol_iterator.ts (compile, jit, rc, own)
  • New interface cases in 00object_dictionary.ts

Verified

  • ctest: 8801 passed, 0 failed (on the rebased branch).
  • wasm32 tester: rc, none and own clean.
  • Full tsc sweep: 3256 → 3262 pass.
    • Now passing: emptyIndexer, inferFromGenericFunctionReturnTypes1, interfaceContextualType, objectIndexer, objectLiteralIndexerNoImplicitAny, propertyAccessOfReadonlyIndexSignature, typeParameterConstrainedToOuterTypeParameter2.
    • Now failing: numericIndexerTyping1. Another interface extends the dictionary interface; the failing line is a type error in TypeScript too. Recorded as open.

Still open, in TSLANG_ISSUES

  • Spreading a dictionary into one with a different value type: needs the default library's objectDictionaryAssign to take two type parameters.
  • Under -mm=own: array growth on write, next(object), and iterator interfaces the program declares itself.

🤖 Generated with Claude Code

… 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>
@ASDAlexander77
ASDAlexander77 merged commit 3de6e2e into main Nov 21, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the tslang-152-153-rest branch November 21, 2026 21:15
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