Repository navigation
Nested arrows with same-named untyped parameters can be instantiated - #542
Merged
Merged
Conversation
An untyped parameter makes its function generic in a type named
TGenParam_<parameter>. In
const getPoint = (x, y) => {
const recenterX = x => (x - screenWidth / 2.0) / screenWidth;
return recenterX(x) + ...;
};
the inner `x`'s type had the same name as the outer `x`'s, so
instantiating getPoint bound the inner arrow's type as well. With a
captured variable (screenWidth) the inner arrow then resolved as a
closure over a function whose type was still generic, and the call
failed: "can't instantiate function ... not all generic types can be
identified". The type is now also named after the function's position.
Found by docs/bugs/generic_in_generic.ts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 11, 2026
ASDAlexander77
added a commit
that referenced
this pull request
Oct 12, 2026
…558) Every repro in docs/bugs passes on main, or fails as TypeScript does: the native_ts_graphics findings were fixed by #535-#544 and #549 (the `let s = 0` one by design, with a warning since #544), testFallThrough, generic_in_generic and array_of_ifaces_cast by #538, #542 and #543, and bug14 and bug21 aren't valid TypeScript. Each fix has its regression test in tslang/test/tester, and the findings document is in the history and in those PRs, so the folder goes. Its interop notes stay, in docs/c-cpp-header-import.md: a `string` returned by a C function is its `char*`, not a copy; `number` is a `double`; and a nullable `Ref<T>` field is spelled `Ref<T> | null`. 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.
Problem
docs/bugs/generic_in_generic.tsfailed to compile:It needs all three of these: an untyped outer arrow, an untyped inner arrow whose parameter has the same name as one of the outer's, and a variable captured from the enclosing function. Renaming the inner
xtozmade it compile.Cause
An untyped parameter makes its function generic in an implicit type parameter named
TGenParam_<parameter name>(processTypeParametersFromFunctionParameters). The innerxtherefore got the same type-parameter name as the outerx. WhengetPointwas instantiated withTGenParam_x = si32, that binding was in scope while the inner arrow was generated, so the inner arrow was named and registered as already specialized (...afL3C20...<si32>, with its capturedscreenWidth) while its type stayed(x: TGenParam_x) => ....resolveFunctionWithCapturethen found the captures under that name and built a bound function with the still-generic type, and nothing instantiates a bound function, so the call failed. (Traced with-debug-only=mliron the debug build.)Fix
getParameterGenericTypeNamealso includes the function's source position in the name (TGenParam_x_<pos>), so nested functions' implicit type parameters can't collide. Both places that build the name (processTypeParametersFromFunctionParametersandprocessTypeArgumentsFromFunctionParameters) use the same signature, so they still agree.Testing
00nested_implicit_generics.ts(compile + JIT + rc/none corpus): the originalrender/getPointcase, an untyped outer function with a capturing same-named inner arrow, and a same-named pair without capture. The current release fails with the error above.docs/bugs/generic_in_generic.tsnow prints 0, 0, 0.016276, done.🤖 Generated with Claude Code