Skip to content

Commit 36907e7

Browse files
Josh PetersonUnityAlex
authored andcommitted
Allow different enums as return type in CreateDelegate (case 1288796)
Allow `CreateDelegate` to have return type covariance with methods that return `enum` or `int` types. This is from the upstream change at mono@1224943.
1 parent 0112b7a commit 36907e7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

mcs/class/corlib/System/Delegate.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ private static bool return_type_match (Type delReturnType, Type returnType) {
160160
// Delegate covariance
161161
if (!returnType.IsValueType && delReturnType.IsAssignableFrom (returnType))
162162
returnMatch = true;
163+
else
164+
{
165+
bool isDelArgEnum = delReturnType.IsEnum;
166+
bool isArgEnum = returnType.IsEnum;
167+
if (isArgEnum && isDelArgEnum)
168+
returnMatch = Enum.GetUnderlyingType(delReturnType) == Enum.GetUnderlyingType(returnType);
169+
else if (isDelArgEnum && Enum.GetUnderlyingType(delReturnType) == returnType)
170+
returnMatch = true;
171+
else if (isArgEnum && Enum.GetUnderlyingType(returnType) == delReturnType)
172+
returnMatch = true;
173+
}
163174
}
164175

165176
return returnMatch;

0 commit comments

Comments
 (0)