Add specific error for extension parameter usage in static members#81606
Merged
Add specific error for extension parameter usage in static members#81606
Conversation
- Added ERR_ExtensionParameterInStaticContext error code (CS9347) - Added error message in CSharpResources.resx - Updated xlf localization files - Modified Binder_Expressions.cs to detect static member case specifically - Updated existing tests to use new error code where applicable Co-authored-by: 333fred <[email protected]>
- Fixed variable naming conflict in Binder_Expressions.cs - Added new error code to ErrorFacts.cs IsBuildOnlyDiagnostic - Added focused test to verify new error message for static context - All extension tests pass (2064 tests) Co-authored-by: 333fred <[email protected]>
- Renamed variable to isStaticContextInExtension for clarity - Added comment explaining why parameter defaults and attributes use general error Co-authored-by: 333fred <[email protected]>
Copilot
AI
changed the title
[WIP] Add dedicated error message for static extension parameter misuse
Add specific error for extension parameter usage in static members
Dec 9, 2025
333fred
reviewed
Dec 9, 2025
jcouv
reviewed
Dec 10, 2025
jcouv
reviewed
Dec 10, 2025
333fred
reviewed
Dec 10, 2025
jcouv
reviewed
Dec 10, 2025
- Refactored complex condition using extracted variables for clarity - Changed error message parameter from full parameter symbol to just parameter.Name - Removed blank line before test method - Updated all test expectations to match new error format (parameter name only, no type) Co-authored-by: 333fred <[email protected]>
jjonescz
reviewed
Dec 10, 2025
333fred
reviewed
Dec 11, 2025
Member
jjonescz
reviewed
Dec 11, 2025
AlekseyTs
reviewed
Dec 11, 2025
AlekseyTs
reviewed
Dec 11, 2025
Contributor
AlekseyTs
reviewed
Dec 11, 2025
Contributor
|
Done with review pass (commit 8) #Closed |
Other review identified concern I'd missed
Member
It was in response to a feedback tweet, not to a filed bug. |
Member
|
@AlekseyTs @jcouv I reverted Binder_Extensions.cs to before this PR, then did the suggested splitting of the condition inside the existing check. I'm going to follow up with a simplification of the outer pattern after this PR. |
AlekseyTs
reviewed
Dec 12, 2025
Contributor
|
Done with review pass (commit 9) #Closed |
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.
Error CS9293 was too generic when extension parameters were referenced from static members, giving "Cannot use extension parameter in this context" without explaining the static/instance mismatch.
Changes
Binder_Expressions.csto detect static member context and emit the specific error with simplified logic using extracted boolean variables for clarity'p'instead of'int p') for concisenessExample
Before: "Cannot use extension parameter 'object o' in this context."
After: "Static members cannot refer to extension parameter 'o'. Use an instance member instead."
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.