Clarify the MA0095 comment about the Equals(object) lookup

Merged
ME
2mo ago
+3-2

What changed

The comment above the MA0095 check in EqualityShouldBeCorrectlyImplementedAnalyzer said:

Check the entire type hierarchy for an Equals(object) override

but the code calls symbol.GetMembers(), which only returns the members declared by the type itself — a base-type override is not visible there. The comment now states what the code does and why.

Why

The behavior is correct and intentional: a type that introduces new equality semantics through IEquatable<T> must override Equals(object) itself, otherwise object.Equals (inherited from the base) and IEquatable<T>.Equals would disagree. This exact shape is listed as non-compliant in docs/Rules/MA0095.md. Only the comment was misleading — it suggested a bug where there is none, and could prompt a "fix" that breaks the rule.

Notes for reviewers

  • Comment-only change; no behavior change.
  • No new test needed: InheritedIEquatable_WithDirectImplementationToo_ShouldTrigger already locks in the scenario (base overrides Equals(object), derived implements IEquatable<Derived> → MA0095 reported).
  • Verified: Meziantou.Analyzer.roslyn5.9 builds with 0 warnings, the 46 EqualityShouldBeCorrectlyImplementedAnalyzerTests tests pass, and dotnet run --project src/DocumentationGenerator exits 0 with no markdown changes.