Skip to content
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 positive for generic class types #7488

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

danpere
Copy link
Contributor

@danpere danpere commented Nov 28, 2024

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.

@danpere danpere requested a review from a team as a code owner November 28, 2024 01:01
@danpere danpere changed the title Fix/enumerable casts/7357 Fix CA2021 false positive for generic class types Nov 28, 2024
@danpere
Copy link
Contributor Author

danpere commented Nov 28, 2024

@dotnet-policy-service agree [company="Microsoft"]

@danpere
Copy link
Contributor Author

danpere commented Nov 28, 2024

@dotnet-policy-service agree company="Microsoft"

Copy link

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.50%. Comparing base (5435ba7) to head (f2eea04).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7488   +/-   ##
=======================================
  Coverage   96.50%   96.50%           
=======================================
  Files        1450     1450           
  Lines      347319   347362   +43     
  Branches    11409    11409           
=======================================
+ Hits       335184   335232   +48     
+ Misses       9244     9241    -3     
+ Partials     2891     2889    -2     

@JoeRobich JoeRobich changed the base branch from main to release/9.0.1xx December 2, 2024 22:38
@JoeRobich JoeRobich changed the base branch from release/9.0.1xx to main December 2, 2024 22:38
Copy link
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @danpere! I make sure this gets back-ported to 9.0.1xx

@JoeRobich JoeRobich merged commit 53b9935 into dotnet:main Dec 3, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants