Conversation
…l value types Previously, value types implementing IEquatable<T> (including ValueTuple) were compared using Equals() instead of structural comparison. This caused issues when structs contained reference type properties (e.g., arrays) that weren't compared structurally. - Remove IEquatable<T> optimization from TypeHelper.IsPrimitiveOrWellKnownType - IsEquivalentTo now always compares struct fields/properties structurally - Users who want Equals() behavior should use IsEqualTo() instead - Add 46 comprehensive tests covering ValueTuple and struct equivalency Fixes #4358 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryFixes IsEquivalentTo to use structural comparison for all value types, resolving issues with ValueTuples and structs containing reference properties. Critical IssuesNone found ✅ AnalysisThis PR correctly addresses issue #4358 by removing the IEquatable optimization for value types in the TypeHelper.IsPrimitiveOrWellKnownType() method. What ChangedThe PR removes lines 90-98 from TypeHelper.cs that treated any value type implementing IEquatable as a "primitive" type. This was causing ValueTuples and structs with reference type fields to use Equals() instead of structural comparison. Why This Is Correct
Test CoverageExcellent - 46 comprehensive tests covering:
TUnit Rules Compliance✅ Dual-Mode: Not applicable (assertions are post-discovery) Code Quality
Verdict✅ APPROVE - This is a correct bug fix with excellent test coverage that follows all TUnit development principles. |
Summary
IsEquivalentTofor ValueTuples and structs containing reference type propertiesIEquatable<T>optimization that caused value types to useEquals()instead of structural comparisonProblem
Previously,
TypeHelper.IsPrimitiveOrWellKnownType()treated any value type implementingIEquatable<T>as a "primitive" type, which meant it usedEquals()instead of structural comparison. This caused issues with:ValueTuple<T1, T2, ...>containing records with array propertiesFor example, this test would fail:
Solution
Removed the
IEquatable<T>check for value types.IsEquivalentToshould always perform structural comparison:Equals()anywayUsers who want
Equals()behavior should useIsEqualTo()instead.Test plan
IEquatable<T>(verifies structural comparison is used, notEquals())Fixes #4358
🤖 Generated with Claude Code