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

Improve handling of incorrect calls to Assert.AreSame #4352

Open
bjornhellander opened this issue Dec 14, 2024 · 3 comments
Open

Improve handling of incorrect calls to Assert.AreSame #4352

bjornhellander opened this issue Dec 14, 2024 · 3 comments

Comments

@bjornhellander
Copy link

bjornhellander commented Dec 14, 2024

It is currently possible to call Assert.AreSame with value reference types. The assertion will fail when the test is run, but it would be better if

  1. this was not possible at all (by constraining the generic type parameter), or
  2. an analyzer could warn immediately about calls that will fail

Not a big problem since the test will fail, but would be nice since it would shorten the time before the mistake was discovered.

@Evangelink
Copy link
Member

Hi @bjornhellander ,

Would you mind giving me an example of what is not working?
AreSame api is basically just a wrapper around object.Referencequal so being able to pass reference seems fine by me.

@bjornhellander
Copy link
Author

Yeah, I messed up. I have edited the description now. I meant value types. So if you mistakenly call AreSame with arguments of a value type, the assert will fail and inform you that you have made a mistake, but it would be nice if the mistake could be immediately apparent instead.

@Evangelink
Copy link
Member

Makes sense!

The goal is to add an analyzer (enabled by default + severity = warning) that would flag calls to Assert.AreSame where 1 side is a value type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants