Skip to content

Commit d27ef43

Browse files
committed
Minimal bugfix: relax return type equality check
The previous commit's test fails due to DynamicProxy treating the base and derived record classes' `<Clone>$` methods as two distinct methods (because they differ in their exact return type), instead of as a single overridden method. We can change this by adjusting `MethodSignature- Comparer` such that it also accepts assignment-compatible return types.
1 parent 2cf79ee commit d27ef43

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Castle.Core/DynamicProxy/Generators/MethodSignatureComparer.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public bool EqualParameters(MethodInfo x, MethodInfo y)
7777
return true;
7878
}
7979

80-
public bool EqualSignatureTypes(Type x, Type y)
80+
public bool EqualSignatureTypes(Type x, Type y, bool precise = true)
8181
{
8282
if (x.IsGenericParameter != y.IsGenericParameter)
8383
{
@@ -122,6 +122,11 @@ public bool EqualSignatureTypes(Type x, Type y)
122122
{
123123
if (!x.Equals(y))
124124
{
125+
if (!precise && y.IsAssignableFrom(x)) // .NET 5+ covariant returns
126+
{
127+
return true;
128+
}
129+
125130
return false;
126131
}
127132
}
@@ -142,7 +147,7 @@ public bool Equals(MethodInfo x, MethodInfo y)
142147

143148
return EqualNames(x, y) &&
144149
EqualGenericParameters(x, y) &&
145-
EqualSignatureTypes(x.ReturnType, y.ReturnType) &&
150+
EqualSignatureTypes(x.ReturnType, y.ReturnType, precise: false) &&
146151
EqualParameters(x, y);
147152
}
148153

0 commit comments

Comments
 (0)