Skip to content

Commit

Permalink
Fix EquatableArray.Equals override to avoid an endless recursion and …
Browse files Browse the repository at this point in the history
…stackoverflow exception (#140)
  • Loading branch information
StefanOssendorf authored Sep 30, 2024
1 parent d00b684 commit 1c7e4c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/StronglyTypedIds/EquatableArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public bool Equals(EquatableArray<T> array)
/// <sinheritdoc/>
public override bool Equals(object? obj)
{
return obj is EquatableArray<T> array && Equals(this, array);
return obj is EquatableArray<T> array && Equals(array);
}

/// <sinheritdoc/>
Expand Down
8 changes: 8 additions & 0 deletions test/StronglyTypedIds.Tests/EqualityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,12 @@ public void ResultWithDiagnosticHasExpectedEqualityBehaviour()
return new Result<(StructToGenerate, bool)>((instance, true), errors);
}
}

[Fact]
public void EquatableArrayOverridenEqualsComparesAsExpected() {
var instance = new EquatableArray<string>(["A"]);
object comparand = new EquatableArray<string>(["A"]);

Assert.True(instance.Equals(comparand));
}
}

0 comments on commit 1c7e4c3

Please sign in to comment.