Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename NeedsDefaultConstraint to HasAnnotatedNullableUsage
The model property now describes what was detected (nullable annotation
on an unconstrained type parameter) rather than what action to take.
The decision to emit `where T : default` remains in the builder layer,
gated by the forExplicitImplementation flag.
  • Loading branch information
thomhurst committed Apr 4, 2026
commit 075c64ed7c6bc09466f39f4531f83ca747d0ac0e
2 changes: 1 addition & 1 deletion TUnit.Mocks.SourceGenerator/Builders/MockImplBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ private static string FormatConstraintClauses(EquatableArray<MockTypeParameterMo
{
clauses.Add($"where {tp.Name} : {tp.Constraints}");
}
else if (forExplicitImplementation && tp.NeedsDefaultConstraint)
else if (forExplicitImplementation && tp.HasAnnotatedNullableUsage)
{
clauses.Add($"where {tp.Name} : default");
}
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Mocks.SourceGenerator/Discovery/MemberDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ private static MockMemberModel CreateMethodModel(IMethodSymbol method, ref int m
{
Name = tp.Name,
Constraints = tp.GetGenericConstraints(),
NeedsDefaultConstraint = tp.IsUnconstrainedWithNullableUsage(method)
HasAnnotatedNullableUsage = tp.IsUnconstrainedWithNullableUsage(method)
}).ToImmutableArray()
),
ExplicitInterfaceName = explicitInterfaceName,
Expand Down
6 changes: 3 additions & 3 deletions TUnit.Mocks.SourceGenerator/Models/MockTypeParameterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ internal sealed record MockTypeParameterModel : IEquatable<MockTypeParameterMode
{
public string Name { get; init; } = "";
public string Constraints { get; init; } = "";
public bool NeedsDefaultConstraint { get; init; }
public bool HasAnnotatedNullableUsage { get; init; }

public bool Equals(MockTypeParameterModel? other)
{
if (other is null) return false;
return Name == other.Name && Constraints == other.Constraints && NeedsDefaultConstraint == other.NeedsDefaultConstraint;
return Name == other.Name && Constraints == other.Constraints && HasAnnotatedNullableUsage == other.HasAnnotatedNullableUsage;
}

public override int GetHashCode()
Expand All @@ -21,7 +21,7 @@ public override int GetHashCode()
int hash = 17;
hash = hash * 31 + Name.GetHashCode();
hash = hash * 31 + Constraints.GetHashCode();
hash = hash * 31 + NeedsDefaultConstraint.GetHashCode();
hash = hash * 31 + HasAnnotatedNullableUsage.GetHashCode();
return hash;
}
}
Expand Down
Loading