Repository navigation
fix: do not throw when the subject of IsEquatableTo is null - #1047
Merged
Merged
Conversation
`IsEquatableTo` called `actual.Equals(expected)` without a null check, so a `null` subject aborted the evaluation with a `NullReferenceException` (surfaced as `InvalidOperationException: Error evaluating ... constraint`) instead of failing the expectation. A `null` subject now fails `IsEquatableTo` and satisfies `IsNotEquatableTo`, consistent with `IsEqualTo`/`IsNotEqualTo`. The constraint also derived from `ConstraintResult.WithValue<IEquatable<T>>` instead of `WithValue<TEquatable>`, which made `TryGetValue` report a type mismatch whenever the constraint succeeded with a `null` subject. Every other constraint passes its own subject type, so the type argument is corrected.
vbreuss
enabled auto-merge (squash)
September 12, 2026 14:15
vbreuss
disabled auto-merge
September 12, 2026 14:16
`IsEquatableToConstraint.AppendNegatedResult` appended " was in " instead of
" was ", so a failing `IsNotEquatableTo` read "but it was in Wrapper { … }".
It was the only occurrence of that wording in the library; `IsOneOf`, which it
appears to have been copied from, does not use it either. The override now
delegates to `AppendNormalResult`, as 153 of the 250 negated-result overrides in
`Source/aweXpect/That` already do.
Contributor
🚀 Benchmark ResultsDetails
|
vbreuss
enabled auto-merge (squash)
September 12, 2026 14:25
|
Contributor
github-actions Bot
added a commit
that referenced
this pull request
Sep 12, 2026
…IsEquatableTo` is `null` (#1047) by Valentin Breuß
github-actions Bot
added a commit
that referenced
this pull request
Sep 12, 2026
…IsEquatableTo` is `null` (#1047) 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.



IsEquatableTocalledactual.Equals(expected)without a null check, so anullsubject aborted the evaluation with aNullReferenceException(surfaced asInvalidOperationException: Error evaluating ... constraint) instead of failing the expectation.A
nullsubject now failsIsEquatableToand satisfiesIsNotEquatableTo, consistent withIsEqualTo/IsNotEqualTo.The constraint also derived from
ConstraintResult.WithValue<IEquatable<T>>instead ofWithValue<TEquatable>, which madeTryGetValuereport a type mismatch whenever the constraint succeeded with anullsubject. Every other constraint passes its own subject type, so the type argument is corrected.