fix: avoid variable shadowing in generated operation code#3740
Merged
timovv merged 4 commits intoAzure:mainfrom Feb 12, 2026
Merged
fix: avoid variable shadowing in generated operation code#3740timovv merged 4 commits intoAzure:mainfrom
timovv merged 4 commits intoAzure:mainfrom
Conversation
When an operation parameter has a name that collides with a local variable in the generated code (e.g. a path parameter named 'path'), the generated code would produce a 'Cannot redeclare' compilation error. Extract generateLocallyUniqueName() from Binder into namingHelpers so it can be reused, and apply it in getSendPrivateFunction (for the 'path' variable) and getOperationFunction (for 'result', 'streamableMethod', 'headers', and 'payload' variables). When there is no conflict the original name is kept; when there is a conflict a suffix is appended (e.g. path_1).
joheredi
approved these changes
Feb 10, 2026
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.
Copilot PR
Problem
When a TypeSpec operation has a parameter whose name collides with a local variable in the generated code, the emitter produces code with a
Cannot redeclarecompilation error.For example, a
@pathparameter namedpathcauses:The same class of bug could also occur with parameters named
result,headers,payload, orstreamableMethodingetOperationFunction.Fix
generateLocallyUniqueName()helper fromBinderintonamingHelpers.tsso it can be reused across the codebase, and updateBinderto import it.getSendPrivateFunction: usegenerateLocallyUniqueName("path", paramNames)so the local variable is renamed topath_1(etc.) only when a parameter namedpathexists.getOperationFunction: apply the same pattern forresult,streamableMethod,headers, andpayload.Testing
pathParameterNamedPath.md) that verifies a@pathparameter namedpathgeneratesconst path_1 = ...instead of shadowing.