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

Do not use ReferenceEquals with impossible types #37691

Open
drewnoakes opened this issue Jun 10, 2020 · 7 comments
Open

Do not use ReferenceEquals with impossible types #37691

drewnoakes opened this issue Jun 10, 2020 · 7 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime code-analyzer Marks an issue that suggests a Roslyn analyzer
Milestone

Comments

@drewnoakes
Copy link
Member

Similar to #33770.

Warn if use of ReferenceEquals would provably always be false based upon the types of the arguments.

Category: Reliability

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Runtime untriaged New issue has not been triaged by the area owner labels Jun 10, 2020
@john-h-k
Copy link
Contributor

john-h-k commented Jun 10, 2020

apart from the obvious

ReferenceEquals(type, typeThatIsntDerivedOrBaseOfOtherType)

would this also apply to value types? Given

ReferenceEquals(someStruct, someStruct)

will always be false currently because they are boxed to different instances. Although, if boxing pooling happened, this could change

@stephentoub
Copy link
Member

@stephentoub stephentoub added the code-analyzer Marks an issue that suggests a Roslyn analyzer label Jun 10, 2020
@stephentoub
Copy link
Member

cc: @bartonjs

@joperezr joperezr removed the untriaged New issue has not been triaged by the area owner label Jul 7, 2020
@joperezr joperezr added this to the Future milestone Jul 7, 2020
@joperezr
Copy link
Member

joperezr commented Jul 7, 2020

@stephentoub do we usually keep issues like this open here or do we usually move them to roslyn repo?

@bartonjs
Copy link
Member

bartonjs commented Jul 7, 2020

@joperezr Analyzer proposals for BCL API live in this repository, so we can review them like API proposals.

But this one was already implemented, as #33766.

@bartonjs bartonjs closed this as completed Jul 7, 2020
@joperezr
Copy link
Member

joperezr commented Jul 7, 2020

I thought the one you pointed at (also @stephentoub pointed at) was only for value types, and this issue was for both that and reference types. Should we reopen to track that part?

@bartonjs bartonjs reopened this Jul 7, 2020
@bartonjs
Copy link
Member

bartonjs commented Jul 7, 2020

Oh, right, yeah. That made sense to me at the time, too. Today, however, I got confused.

@buyaa-n buyaa-n added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime code-analyzer Marks an issue that suggests a Roslyn analyzer
Projects
None yet
Development

No branches or pull requests

7 participants