Skip to content

Commit 6238c15

Browse files
committed
Also check for covariant return types if one of them is generic
1 parent 06884f4 commit 6238c15

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private bool EqualSignatureTypes(Type x, Type y, MethodInfo xm = null, MethodInf
9292
}
9393
else if (x.IsGenericType != y.IsGenericType)
9494
{
95-
return false;
95+
return IsCovariantReturnTypes(x, y, xm, ym);
9696
}
9797

9898
if (x.IsGenericParameter)
@@ -129,19 +129,24 @@ private bool EqualSignatureTypes(Type x, Type y, MethodInfo xm = null, MethodInf
129129
{
130130
if (!x.Equals(y))
131131
{
132-
// This enables covariant method returns for .NET 5 and newer.
133-
// No need to check for runtime support, since such methods are marked with a custom attribute;
134-
// see https://github.com/dotnet/runtime/blob/main/docs/design/features/covariant-return-methods.md.
135-
if (preserveBaseOverridesAttribute != null)
136-
{
137-
return (xm != null && xm.IsDefined(preserveBaseOverridesAttribute, inherit: false) && y.IsAssignableFrom(x))
138-
|| (ym != null && ym.IsDefined(preserveBaseOverridesAttribute, inherit: false) && x.IsAssignableFrom(y));
139-
}
140-
141-
return false;
132+
return IsCovariantReturnTypes(x, y, xm, ym);
142133
}
143134
}
144135
return true;
136+
137+
static bool IsCovariantReturnTypes(Type x, Type y, MethodInfo xm, MethodInfo ym)
138+
{
139+
// This enables covariant method returns for .NET 5 and newer.
140+
// No need to check for runtime support, since such methods are marked with a custom attribute;
141+
// see https://github.com/dotnet/runtime/blob/main/docs/design/features/covariant-return-methods.md.
142+
if (preserveBaseOverridesAttribute != null)
143+
{
144+
return (xm != null && xm.IsDefined(preserveBaseOverridesAttribute, inherit: false) && y.IsAssignableFrom(x))
145+
|| (ym != null && ym.IsDefined(preserveBaseOverridesAttribute, inherit: false) && x.IsAssignableFrom(y));
146+
}
147+
148+
return false;
149+
}
145150
}
146151

147152
public bool Equals(MethodInfo x, MethodInfo y)

0 commit comments

Comments
 (0)