NUnit2040 helps guide for correct usage of the SameAs constraint by alerting to value types passed in as value types can't be reference-equal. It will raise an error if it detects these.
One edge case is around nullable value types. The below code will alert an error by the analyzer but the assertion itself will pass.
int? index = default;
Assert.That(index, Is.SameAs(index));
A few options I could think of:
- Do not alert at all for nullable value types
- Raise a warning instead of an error for nullable value types