Skip to content

Commit fa990fb

Browse files
diegofrataclaude
andcommitted
chore: remove dead code and simplify redundant state
- Remove unused AnyAncestorHasEquatable method and NearestComparerAncestorFullname property (set but never read) - Make EqualityMemberModel.Ignored a derived property from EqualityType, removing redundant explicit assignments and double-check guard - Simplify SetEqualityComparer by deriving custom-comparer detection via ReferenceEquals instead of tracking a separate boolean field - Remove inconsistent internal modifier from TypeSymbolExtensions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 18c7aad commit fa990fb

7 files changed

Lines changed: 6 additions & 29 deletions

File tree

Generator.Equals.Runtime/SetEqualityComparer.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,13 @@ public class SetEqualityComparer<T> : IEqualityComparer<IEnumerable<T>>
1111

1212
public IEqualityComparer<T> EqualityComparer { get; }
1313

14-
readonly bool _hasCustomComparer;
15-
16-
public SetEqualityComparer() : this(DefaultEqualityComparer<T>.Default, hasCustomComparer: false)
14+
public SetEqualityComparer() : this(DefaultEqualityComparer<T>.Default)
1715
{
1816
}
1917

2018
public SetEqualityComparer(IEqualityComparer<T> equalityComparer)
21-
: this(equalityComparer, hasCustomComparer: true)
22-
{
23-
}
24-
25-
SetEqualityComparer(IEqualityComparer<T> equalityComparer, bool hasCustomComparer)
2619
{
2720
EqualityComparer = equalityComparer;
28-
_hasCustomComparer = hasCustomComparer;
2921
}
3022

3123
public bool Equals(IEnumerable<T>? x, IEnumerable<T>? y)
@@ -38,7 +30,7 @@ public bool Equals(IEnumerable<T>? x, IEnumerable<T>? y)
3830

3931
// When no custom comparer was specified, delegate to the set's own
4032
// comparer so we respect whatever the collection was built with.
41-
if (!_hasCustomComparer)
33+
if (ReferenceEquals(EqualityComparer, DefaultEqualityComparer<T>.Default))
4234
{
4335
if (x is ISet<T> xSet)
4436
return xSet.SetEquals(y);

Generator.Equals/EqualityGeneratorBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static string GetComparerEquals(EqualityMemberModel memberModel, string left, st
315315

316316
static void BuildMemberInequality(EqualityMemberModel memberModel, IndentedTextWriter writer, string left, string right, string pathExpr)
317317
{
318-
if (memberModel.Ignored || memberModel.EqualityType == EqualityType.IgnoreEquality)
318+
if (memberModel.Ignored)
319319
{
320320
return;
321321
}

Generator.Equals/EqualityMemberModelTransformer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public static EqualityMemberModel BuildEqualityModel(
109109
MemberName = propertyName, IsField = isField,
110110
TypeName = typeName,
111111
EqualityType = EqualityType.IgnoreEquality,
112-
Ignored = true,
113112
};
114113
}
115114

@@ -273,7 +272,6 @@ public static EqualityMemberModel BuildEqualityModel(
273272
MemberName = propertyName, IsField = isField,
274273
TypeName = typeName,
275274
EqualityType = isIgnored ? EqualityType.IgnoreEquality : EqualityType.DefaultEquality,
276-
Ignored = isIgnored
277275
};
278276
}
279277
}

Generator.Equals/EqualityTypeModelTransformer.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ public EqualityTypeModelTransformer(GeneratorAttributeSyntaxContext context)
8484
// reach a meaningful equality implementation. We walk up the inheritance chain
8585
// to find if any ancestor has a generated EqualityComparer. If so, we should call
8686
// that ancestor's comparer.
87-
var nearestComparerAncestor = FindNearestComparerAncestor(symbol.BaseType, attributesMetadata);
88-
var baseHasEquatable = nearestComparerAncestor != null;
89-
var nearestComparerAncestorFullname = nearestComparerAncestor?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
87+
var baseHasEquatable = FindNearestComparerAncestor(symbol.BaseType, attributesMetadata) != null;
9088

9189
var bems = EqualityMemberModelTransformer.BuildEqualityModels(symbol, attributesMetadata, explicitMode, filter);
9290

@@ -107,7 +105,6 @@ public EqualityTypeModelTransformer(GeneratorAttributeSyntaxContext context)
107105
IsSealed = symbol.IsSealed,
108106
BaseTypeName = baseTypeName,
109107
BaseTypeFullname = baseTypeFullname,
110-
NearestComparerAncestorFullname = nearestComparerAncestorFullname,
111108
Fullname = fullname,
112109
SyntaxKind = _context.TargetNode.Kind(),
113110
BaseHasEquatable = baseHasEquatable,
@@ -180,10 +177,6 @@ static bool HasGeneratedEqualityComparer(INamedTypeSymbol type)
180177
/// This includes types with [Equatable] attribute or types with a generated EqualityComparer (for cross-assembly).
181178
/// If so, calling the base comparer will reach that implementation.
182179
/// </summary>
183-
static bool AnyAncestorHasEquatable(INamedTypeSymbol? baseType, AttributesMetadata attributesMetadata)
184-
{
185-
return FindNearestComparerAncestor(baseType, attributesMetadata) != null;
186-
}
187180

188181
/// <summary>
189182
/// Collects all properties from ancestor types that don't have [Equatable] or a generated EqualityComparer.

Generator.Equals/Extensions/TypeSymbolExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Generator.Equals.Extensions;
88
/// <summary>
99
/// Extension methods for <see cref="ITypeSymbol"/> used by the analyzer.
1010
/// </summary>
11-
internal static class TypeSymbolExtensions
11+
static class TypeSymbolExtensions
1212
{
1313
private static readonly HashSet<string> PrimitiveTypeNames = new()
1414
{

Generator.Equals/Models/EqualityMemberModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ sealed record EqualityMemberModel
1414
public double? Precision { get; init; }
1515
public bool IsNullable { get; init; }
1616

17-
public bool Ignored { get; init; }
17+
public bool Ignored => EqualityType == EqualityType.IgnoreEquality;
1818
public bool ComparerHasStaticInstance { get; init; }
1919

2020
// Element comparer properties for collection equality attributes

Generator.Equals/Models/EqualityTypeModel.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ sealed record EqualityTypeModel
1515
/// </summary>
1616
public string? BaseTypeFullname { get; init; }
1717

18-
/// <summary>
19-
/// Fully qualified name of the nearest ancestor that has a generated EqualityComparer.
20-
/// This is used when the immediate base doesn't have a comparer but an ancestor does.
21-
/// </summary>
22-
public string? NearestComparerAncestorFullname { get; init; }
23-
2418
public required bool IsSealed { get; init; }
2519
public required EquatableImmutableArray<ContainingSymbol> ContainingSymbols { get; init; }
2620
public required AttributesMetadata AttributesMetadata { get; init; }

0 commit comments

Comments
 (0)