-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add specific error for extension parameter usage in static members #81606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 <2371880+333fred@users.noreply.github.com>
- 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 <2371880+333fred@users.noreply.github.com>
- Renamed variable to isStaticContextInExtension for clarity - Added comment explaining why parameter defaults and attributes use general error Co-authored-by: 333fred <2371880+333fred@users.noreply.github.com>
- 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 <2371880+333fred@users.noreply.github.com>
jcouv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (commit 8)
|
Done with review pass (commit 8) #Closed |
Other review identified concern I'd missed
It was in response to a feedback tweet, not to a filed bug. |
|
@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. |
|
Done with review pass (commit 9) #Closed |
AlekseyTs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 10)
jcouv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (commit 10)
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.