-
Notifications
You must be signed in to change notification settings - Fork 14
feat: implement separate diagnostics for variables named '_' and unnecessary typed discards #889
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
2ff47e5
e258323
6a77a15
bfa4aca
b37baeb
52157e6
4c09002
55b6e25
eace4ef
73e78d6
65d633b
debb243
5886208
31a38e3
3cbca61
20f5320
3b354e8
7f47db2
2cf2205
ca958e1
96df7cd
e259040
2caf4c6
ff42244
bb980db
f9ec0d3
3d6c231
23cb422
9271a0f
fe12417
d1b2b7e
1f4965b
9eb5794
4701aa2
14f6f88
28f94a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,17 +98,23 @@ private void AnalyzeArgument(SyntaxNodeAnalysisContext context) | |
| return; | ||
| } | ||
|
|
||
| Location location = variable.Identifier.GetLocation(); | ||
| var diagnostic = Diagnostic.Create(Rule, location, variable.Identifier.ValueText); | ||
| context.ReportDiagnostic(diagnostic); | ||
| } | ||
| else if (declaration.Designation is DiscardDesignationSyntax discard) | ||
| { | ||
| Location location = discard.UnderscoreToken.GetLocation(); | ||
| var diagnostic = Diagnostic.Create(Rule, location, discard.UnderscoreToken.ValueText); | ||
| context.ReportDiagnostic(diagnostic); | ||
| // This is a typed discard (e.g., out int _) | ||
| // Check if anonymous discard would work without causing overload resolution issues | ||
| if (!IsTypedDiscardNecessaryForOverloadResolution(context, argument)) | ||
| { | ||
| Location location = variable.Identifier.GetLocation(); | ||
| var diagnostic = Diagnostic.Create(Rule, location, variable.Identifier.ValueText); | ||
| context.ReportDiagnostic(diagnostic); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #pragma warning disable IDE0060 // Remove unused parameter | ||
| private bool IsTypedDiscardNecessaryForOverloadResolution(SyntaxNodeAnalysisContext context, ArgumentSyntax argument) | ||
| { | ||
| return false; | ||
|
||
| } | ||
| #pragma warning restore IDE0060 // Remove unused parameter | ||
| } | ||
| } | ||
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.
do not use pragmas. fix the code instead.
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.
Fixed by removing the pragmas and implementing proper semantic analysis in the method. The pragmas were replaced with a comprehensive implementation that analyzes method overloads using the semantic model. Commit bfa4aca.