Skip to content

Commit

Permalink
Improve Delegate instance matching
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Sep 2, 2024
1 parent 82573dd commit 38a4cf6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ILRuntime/Runtime/Intepreter/DelegateAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ public override bool CanAssignTo(IType type)
}
if (im.IsDelegateInvoke)
{
if (im.ParameterCount == method_count && ret_type == method.ReturnType)
if (im.ParameterCount == method_count && method.ReturnType.CanAssignTo(ret_type))
{

for (int i = 0; i < im.ParameterCount; i++)
Expand Down
9 changes: 8 additions & 1 deletion ILRuntime/Runtime/Intepreter/ILIntepreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3628,7 +3628,14 @@ public object Run(ILMethod method, object instance, object[] p)
}
else
{
throw new InvalidCastException(string.Format("Cannot Cast {0} to {1}", ((ILTypeInstance)obj).Type.FullName, type.FullName));
string curType;
if (type.IsDelegate)
{
curType = $"{((DelegateAdapter)obj).Method.DeclearingType.FullName}.{((DelegateAdapter)obj).Method.Name}";
}
else
curType = ((ILTypeInstance)obj).Type.FullName;
throw new InvalidCastException(string.Format("Cannot Cast {0} to {1}", curType, type.FullName));
}
}
else
Expand Down

0 comments on commit 38a4cf6

Please sign in to comment.