Skip to content

Commit

Permalink
Compare references correctly to avoid AOT error. Fix Tencent#400
Browse files Browse the repository at this point in the history
  • Loading branch information
UlyssesWu committed Jul 20, 2023
1 parent 552da36 commit d436af9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Source/VSProj/Src/Tools/CodeTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ int addInternString(string str, MethodDefinition caller)
return id;
}

private static bool IsMemberReferenceEqual(MemberReference t1, MemberReference t2)
{
return t1.FullName == t2.FullName &&
t1.Module.Assembly.FullName == t2.Module.Assembly.FullName;
}

private static bool IsAsyncMethodBuilderMethodEqual(GenericInstanceMethod m1, GenericInstanceMethod m2)
{
return IsMemberReferenceEqual(m1.GenericArguments[0], m2.GenericArguments[0]) && m1.DeclaringType?.FullName == m2.DeclaringType?.FullName;
}

//原生方法的引用
int addExternMethod(MethodReference callee, MethodDefinition caller)
{
Expand All @@ -276,8 +287,7 @@ int addExternMethod(MethodReference callee, MethodDefinition caller)

if (callee.Name == "AwaitUnsafeOnCompleted")
{

if (!awaitUnsafeOnCompletedMethods.Any(m => ((GenericInstanceMethod)callee).GenericArguments[0] == ((GenericInstanceMethod)m).GenericArguments[0]))
if (awaitUnsafeOnCompletedMethods.All(m => !IsAsyncMethodBuilderMethodEqual((GenericInstanceMethod)callee, (GenericInstanceMethod)m)))
{
awaitUnsafeOnCompletedMethods.Add(callee);
}
Expand Down

0 comments on commit d436af9

Please sign in to comment.