Repository navigation
fix!: treat IsSameAs as a comparison for a null subject - #1068
Merged
Merged
Conversation
`Expect.That((object?)null).IsSameAs(null)` failed with "refers to <null>, but it was <null>", although `ReferenceEquals(null, null)` is true. The constraint was built on `WithNotNullValue`, which fails for a `null` subject whatever it is compared with. Identity is a comparison against a value the caller supplies, so `null` is an ordinary value on both sides, exactly as for `IsEqualTo`. `WithEqualToValue` expresses that: for a `null` subject, `IsSameAs(null)` and `IsNotSameAs(other)` now succeed, while `IsSameAs(other)` and `IsNotSameAs(null)` still fail. This is the one change in this series that loosens behaviour rather than tightening it, which is why it is separate. Both expectations lose their `[GuaranteesNotNull]` marking, because a `null` subject can now satisfy them: a right answer is worth more than a suppressed nullability warning. BREAKING CHANGE: `IsSameAs(null)` and `IsNotSameAs(other)` now succeed for a `null` subject instead of failing, and neither expectation proves the subject to be not `null` for the analyzer any more.
`IsSameAs` and `IsNotSameAs` no longer carry `[GuaranteesNotNull]`. The regenerated files also pick up `ThatVersion`, which #1061 added without updating the snapshots - the approval tests are red on `main` until this lands.
vbreuss
force-pushed
the
fix/null-philosophy-is-same-as
branch
from
September 13, 2026 07:15
05bd214 to
56a1397
Compare
Contributor
🚀 Benchmark ResultsDetails
|
Contributor
👽 Mutation ResultsaweXpectDetails
The final mutation score is 100.00%Coverage Thresholds: high:80 low:60 break:0aweXpect.CoreDetails
The final mutation score is NaN%Coverage Thresholds: high:80 low:60 break:0 |
Contributor
Test Results 23 files - 27 23 suites - 27 10m 37s ⏱️ +55s Results for commit 56a1397. ± Comparison against base commit 80d7a63. This pull request removes 3236 and adds 3200 tests. Note that renamed tests count towards both. |
|
github-actions Bot
added a commit
that referenced
this pull request
Sep 13, 2026
…for a `null` subject (#1068) by Valentin Breuß
github-actions Bot
added a commit
that referenced
this pull request
Sep 13, 2026
…for a `null` subject (#1068) by Valentin Breuß
This was referenced Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Expect.That((object?)null).IsSameAs(null)failed with "refers to , but it was ", althoughReferenceEquals(null, null)is true. The constraint was built onWithNotNullValue, which fails for anullsubject whatever it is compared with.Identity is a comparison against a value the caller supplies, so
nullis an ordinary value on both sides, exactly as forIsEqualTo.WithEqualToValueexpresses that: for anullsubject,IsSameAs(null)andIsNotSameAs(other)now succeed, whileIsSameAs(other)andIsNotSameAs(null)still fail.This is the one change in this series that loosens behaviour rather than tightening it, which is why it is separate. Both expectations lose their
[GuaranteesNotNull]marking, because anullsubject can now satisfy them: a right answer is worth more than a suppressed nullability warning.BREAKING CHANGE:
IsSameAs(null)andIsNotSameAs(other)now succeed for anullsubject instead of failing, and neither expectation proves the subject to be notnullfor the analyzer any more.