-
Notifications
You must be signed in to change notification settings - Fork 470
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
fix CA2021 false positives #7183
Conversation
8404737
to
de9cac1
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #7183 +/- ##
==========================================
- Coverage 96.44% 96.44% -0.01%
==========================================
Files 1415 1415
Lines 338191 338229 +38
Branches 11191 11191
==========================================
+ Hits 326166 326201 +35
- Misses 9205 9209 +4
+ Partials 2820 2819 -1 |
...tCore.Analyzers/Runtime/DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
I think |
…/DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesAnalyzerTests.cs
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, thank you @fowl2 for quick fix
...tCore.Analyzers/Runtime/DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesAnalyzerTests.cs
Show resolved
Hide resolved
…/DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesAnalyzerTests.cs
Fix for #7357. #7183 changed the CastWillAlwaysFail(ITypeSymbol castFrom, ITypeSymbol castTo) to work with castFrom.OriginalDefinition/castTo.OriginalDefinition, eliding the generic type information in order to fix issues with interfaces, but that appears to have broken the check for class types. This reverts just the class type case to use the castFrom/castTo types passed in instead of the .OriginalDefinition. I'm not sure I quite understand why that's the only place this matters, but I tried a few variations with structs and interfaces and couldn't get any other false positives.
Can't say I really understand this that well, but adds the test case and fixes #7153 without breaking anything else as far I can tell.
The code was previously using
ITypeSymbol
propertyAllInterfaces
which says the seemly relevantly:So this change sprinkles some
OriginalDefinition
calls around, and switches to usingDerivesFrom
- which callsOriginalDefinition
on all the interface symbols before checking equality.