Fix declaration emit renaming a method's shadowed type parameter to the outer generic#3761
Open
Fix declaration emit renaming a method's shadowed type parameter to the outer generic#3761
Conversation
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/2dd0795c-09cb-4be6-bea9-47c121c1582e Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix declaration emit renaming method's shadowed type parameter
Fix declaration emit renaming a method's shadowed type parameter to the outer generic
May 8, 2026
jakebailey
reviewed
May 8, 2026
Comment on lines
54
to
67
| if ast.IsFunctionLike(location) && lastLocation != nil && lastLocation != location.Body() { | ||
| // symbol lookup restrictions for function-like declarations | ||
| // - Type parameters of a function are in scope in the entire function declaration, including the parameter | ||
| // list and return type. However, local types are only in scope in the function body. | ||
| // - parameters are only in the scope of function body | ||
| if meaning&result.Flags&ast.SymbolFlagsType != 0 { | ||
| useResult = result.Flags&ast.SymbolFlagsTypeParameter != 0 && (lastLocation == location.Type() || ast.IsParameterLike(lastLocation)) | ||
| // type parameters are visible in parameter list, return type and type parameter list. | ||
| // Synthetic fake scopes are added for signatures so type parameters are accessible from them. | ||
| useResult = result.Flags&ast.SymbolFlagsTypeParameter != 0 && | ||
| (lastLocation.Flags&ast.NodeFlagsSynthesized != 0 || | ||
| lastLocation == location.Type() || | ||
| ast.IsParameterLike(lastLocation)) | ||
| } | ||
| if meaning&result.Flags&ast.SymbolFlagsVariable != 0 { |
Member
There was a problem hiding this comment.
This was:
if (isFunctionLike(location) && lastLocation && lastLocation !== (location as FunctionLikeDeclaration).body) {
// symbol lookup restrictions for function-like declarations
// - Type parameters of a function are in scope in the entire function declaration, including the parameter
// list and return type. However, local types are only in scope in the function body.
// - parameters are only in the scope of function body
// This restriction does not apply to JSDoc comment types because they are parented
// at a higher level than type parameters would normally be
if (meaning & result.flags & SymbolFlags.Type && lastLocation.kind !== SyntaxKind.JSDoc) {
useResult = result.flags & SymbolFlags.TypeParameter
// type parameters are visible in parameter list, return type and type parameter list
? !!(lastLocation.flags & NodeFlags.Synthesized) || // Synthetic fake scopes are added for signatures so type parameters are accessible from them
lastLocation === (location as FunctionLikeDeclaration).type ||
lastLocation.kind === SyntaxKind.Parameter ||
lastLocation.kind === SyntaxKind.JSDocParameterTag ||
lastLocation.kind === SyntaxKind.JSDocReturnTag ||
lastLocation.kind === SyntaxKind.TypeParameter
// local types not visible outside the function body
: false;
}
if (meaning & result.flags & SymbolFlags.Variable) {Even though this appears to regress some cases (but, improve diffs!), I think probably this is a correct fix
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a name-resolution bug in the Go port’s binder that caused declaration emit to incorrectly bind a method’s shadowing type parameter to an outer generic when signature scopes are represented by synthesized “fake scope” nodes. This aligns tsgo’s type-parameter visibility rules with the TypeScript reference implementation and updates baselines accordingly.
Changes:
- Update
NameResolver.Resolveto treatNodeFlagsSynthesizedas a valid context for type-parameter visibility when walking function-like scopes. - Add a focused regression test covering a method type parameter shadowing an outer class type parameter during
.d.tsemit. - Refresh baselines and prune
submoduleAccepted.txtby removing now-unnecessary accepted.types.difffiles after behavior convergence.
Reviewed changes
Copilot reviewed 177 out of 177 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/binder/nameresolver.go | Fixes type-parameter lookup across synthesized signature scopes so shadowing doesn’t resolve to the outer generic. |
| testdata/tests/cases/compiler/declarationEmitMethodShadowsClassTypeParameter.ts | Adds a regression test reproducing the shadowed-type-parameter declaration emit issue. |
| testdata/submoduleAccepted.txt | Removes entries for accepted diffs that are no longer needed after behavior changes. |
| testdata/baselines/reference/compiler/declarationEmitMethodShadowsClassTypeParameter.types | New/updated expected baseline for the added regression test (types). |
| testdata/baselines/reference/compiler/declarationEmitMethodShadowsClassTypeParameter.symbols | New/updated expected baseline for the added regression test (symbols). |
| testdata/baselines/reference/compiler/declarationEmitMethodShadowsClassTypeParameter.js | New/updated expected baseline for the added regression test (JS + .d.ts emit section). |
| testdata/baselines/reference/submoduleAccepted/compiler/infinitelyExpandingTypes5.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/inferenceDoesNotAddUndefinedOrNull.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/genericOverloadSignatures.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/genericMemberFunction.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/genericFunctionSpecializations1.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/genericFunctions3.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/genericFunctionInference1.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/genericCombinators2.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/functionOverloadsRecursiveGenericReturnType.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/functionOverloadsOnGenericArity2.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/fixingTypeParametersRepeatedly3.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/fixingTypeParametersRepeatedly2.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/duplicateOverloadInTypeAugmentation1.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/contravariantInferenceAndTypeGuard.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/coAndContraVariantInferences3.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submoduleAccepted/compiler/callbacksDontShareTypes.types.diff | Removes an accepted diff now obsolete due to updated type-parameter naming behavior. |
| testdata/baselines/reference/submodule/conformance/variadicTuples1.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/variadicTuples1.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/typeParametersAvailableInNestedScope3.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/typeParametersAvailableInNestedScope3.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/typeParameterConstModifiersReturnsAndYields.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/typeParameterConstModifiersReturnsAndYields.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/tsxStatelessFunctionComponentsWithTypeArguments4.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/tsxStatelessFunctionComponentsWithTypeArguments4.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/templateLiteralTypes1.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/templateLiteralTypes1.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/taggedTemplateStringsWithOverloadResolution3.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/taggedTemplateStringsWithOverloadResolution3.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/taggedTemplateStringsWithOverloadResolution3_ES6.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/taggedTemplateStringsWithOverloadResolution3_ES6.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/taggedTemplateContextualTyping1.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/taggedTemplateContextualTyping1.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/subtypesOfTypeParameter.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/subtypesOfTypeParameter.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/stringLiteralTypeIsSubtypeOfString.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/recursiveTypesUsedAsFunctionParameters.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/recursiveTypesUsedAsFunctionParameters.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/parenthesizedContexualTyping3.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/parenthesizedContexualTyping3.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/parenthesizedContexualTyping2.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/parenthesizedContexualTyping2.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/parenthesizedContexualTyping1.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/parenthesizedContexualTyping1.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/overloadResolution.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/overloadResolution.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/methodSignaturesWithOverloads2.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/methodSignaturesWithOverloads2.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/methodSignaturesWithOverloads.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/methodSignaturesWithOverloads.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/keyofAndIndexedAccess.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/keyofAndIndexedAccess.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/jsDeclarationsInterfaces(target=es2015).types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/jsDeclarationsInterfaces(target=es2015).types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/instantiationExpressions.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/instantiationExpressions.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/genericClassWithObjectTypeArgsAndConstraints.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/genericClassWithObjectTypeArgsAndConstraints.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/genericClassWithFunctionTypedMemberArguments.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/genericClassWithFunctionTypedMemberArguments.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/genericCallWithConstraintsTypeArgumentInference.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/genericCallWithConstraintsTypeArgumentInference.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/genericCallTypeArgumentInference.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/genericCallTypeArgumentInference.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/functionLiterals.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/functionLiterals.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/conditionalTypes2.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/conditionalTypes2.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/bivariantInferences.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/conformance/bivariantInferences.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/variableDeclaratorResolvedDuringContextualTyping.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/variableDeclaratorResolvedDuringContextualTyping.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/undefinedTypeArgument2.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/undefinedTypeArgument2.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/typeArgumentConstraintResolution1.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/typeArgumentConstraintResolution1.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/twiceNestedKeyofIndexInference.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/twiceNestedKeyofIndexInference.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/tupleTypeInference.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/tupleTypeInference.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/tslibReExportHelpers2.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/tslibReExportHelpers2.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/tooFewArgumentsInGenericFunctionTypedArgument.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/tooFewArgumentsInGenericFunctionTypedArgument.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/thisInTupleTypeParameterConstraints.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/thisInTupleTypeParameterConstraints.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/styledComponentsInstantiaionLimitNotReached.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/styledComponentsInstantiaionLimitNotReached.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/specializationError.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/specializationError.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/promises.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/promises.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/overloadsWithConstraints.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/overloadsWithConstraints.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/overloadsAndTypeArgumentArity.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/overloadsAndTypeArgumentArity.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/overloadGenericFunctionWithRestArgs.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/overloadGenericFunctionWithRestArgs.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/overloadEquivalenceWithStatics.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/overloadEquivalenceWithStatics.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/overloadedStaticMethodSpecialization.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/overloadedStaticMethodSpecialization.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/objectLiteralParameterResolution.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/objectLiteralParameterResolution.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/noImplicitReturnsExclusions.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/noImplicitReturnsExclusions.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/missingTypeArguments3.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/missingTypeArguments3.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/mismatchedGenericArguments1.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/mismatchedGenericArguments1.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/jsxGenericComponentWithSpreadingResultOfGenericFunction.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/jsxGenericComponentWithSpreadingResultOfGenericFunction.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/infinitelyExpandingTypes5.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/inferenceDoesNotAddUndefinedOrNull.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/genericOverloadSignatures.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/genericMemberFunction.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/genericFunctionSpecializations1.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/genericFunctions3.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/genericFunctionInference1.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/genericCombinators2.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/functionOverloadsRecursiveGenericReturnType.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/functionOverloadsOnGenericArity2.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/fixingTypeParametersRepeatedly3.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/fixingTypeParametersRepeatedly2.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/duplicateOverloadInTypeAugmentation1.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/contravariantInferenceAndTypeGuard.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/coAndContraVariantInferences3.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/callbacksDontShareTypes.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/compiler/jsExportsImportedIntoTsxLosesTypeInfo.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/declarationEmitShadowing.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/declarationEmitShadowing.types | Updates expected baseline output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/declarationEmitOverloadedPrivateInference.types.diff | Updates/cleans up expected diff output due to corrected type-parameter naming. |
| testdata/baselines/reference/submodule/compiler/declarationEmitOverloadedPrivateInference.types | Updates expected baseline output due to corrected type-parameter naming. |
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.
When a method's type parameter shadowed its enclosing class's type parameter, declaration emit renamed the inner parameter to a
_1alias of the outer one, so the emitted return type bound to the wrong generic:Root cause
NameResolver.Resolvewas missing aNodeFlagsSynthesizedcheck for type-parameter lookups through a function-like location.The nodebuilder's
enterNewScopepushes syntheticBlockfake-scopes (parented to the method) to hold params/type-params. WhentypeParameterShadowsOtherTypeParameterInScopecallsresolveName, the walk traverses[synthetic Block] → [MethodDeclaration] → [ClassDeclaration]. At the method, the innerTablewas found inlocation.Locals(), but rejected becauselastLocation(the synthetic Block) was neitherlocation.Type()norIsParameterLike. The walk fell through to the class, returned the outerTable, and triggered the rename.The variable branch already had the equivalent
Synthesizedcheck; only the type-parameter branch was missing it.Changes
internal/binder/nameresolver.go: in the function-like scope-restriction logic, acceptlastLocation.Flags & NodeFlagsSynthesized != 0as a valid context for a type parameter to remain visible, matchingutilities.ts:11545-11563in the TypeScript reference.testdata/tests/cases/compiler/declarationEmitMethodShadowsClassTypeParameter.ts: focused regression test mirroring the issue repro..types.difffiles removed (andsubmoduleAccepted.txtpruned accordingly) because tsgo now matches the TypeScript reference for type-parameter naming in many additional cases beyond the reported one.