Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复Stfld与Ldfld当对象为适配器时的异常 #655

Merged
merged 2 commits into from
Feb 10, 2022

Conversation

Endures
Copy link
Contributor

@Endures Endures commented Feb 8, 2022

在测试用例源码文件InheritanceTest.cs中增加如下2个用例

CrossClass crossClass;
public static void InheritanceTest21()
{
    var inheritanceTest = new InheritanceTest();
    var dic = new Dictionary<int, CrossClass>();
    dic.Add(1, new CrossClass());
    dic.TryGetValue(1, out inheritanceTest.crossClass);
    Console.WriteLine("InheritanceTest21:classA is " + inheritanceTest.crossClass.classA);
}

public static void InheritanceTest22()
{
    var inheritanceTest = new InheritanceTest();
    var dic = new Dictionary<int, CrossClass>();
    dic.Add(1, new CrossClass());
    dic.TryGetValue(1, out inheritanceTest.crossClass);
    inheritanceTest.crossClass.classA = new ClassA();
    Console.WriteLine("InheritanceTest21:classA is " + inheritanceTest.crossClass.classA);
}

其中InheritanceTest21报如下异常

无法将类型为“ILRuntime.CLR.TypeSystem.ILType”的对象强制转换为类型“ILRuntime.CLR.TypeSystem.CLRType”。
Local Variables:
InheritanceTest inheritanceTest = TestCases.InheritanceTest, Dictionary`2 dic = System.Collections.Generic.Dictionary`2[System.Int32,ILRuntimeTest.TestFramework.TestClass3Adaptor+Adaptor]

IL_0033: ldfld TestCases.InheritanceTest/ClassA TestCases.InheritanceTest/CrossClass::classA
at TestCases.InheritanceTest.InheritanceTest21() (at C:/Users/Administrator/source/repos/Endures/ILRuntime/TestCases/InheritanceTest.cs:302)

System.InvalidCastException: 无法将类型为“ILRuntime.CLR.TypeSystem.ILType”的对象强制转换为类型“ILRuntime.CLR.TypeSystem.CLRType”。
   在 ILRuntime.Runtime.Intepreter.ILIntepreter.Execute(ILMethod method, StackObject* esp, Boolean& unhandledException) 位置 C:\Users\Administrator\source\repos\Endures\ILRuntime\ILRuntime\Runtime\Intepreter\ILIntepreter.cs:行号 2252

原因为未处理局部变量obj为适配器类型(CrossBindingAdaptorType)的情况
用例InheritanceTest22同理

@@ -2105,9 +2105,13 @@ public object Run(ILMethod method, object instance, object[] p)

if (obj != null)
{
if (obj is ILTypeInstance)
ILTypeInstance instance = null;
if (obj is ILTypeInstance ilTypeInstance)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请不要使用c# 7以上的语法,会导致老版本Unity无法使用,需要修改

ILTypeInstance instance = null;
if (obj is ILTypeInstance ilTypeInstance)
instance = ilTypeInstance;
else if (obj is CrossBindingAdaptorType crossBindingAdaptorType)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

ILRuntime/Runtime/Intepreter/ILIntepreter.cs Outdated Show resolved Hide resolved
@Endures
Copy link
Contributor Author

Endures commented Feb 10, 2022

修改代码然后重新创建一个pull request么?

@liiir1985
Copy link
Collaborator

修改代码然后重新创建一个pull request么?

直接在当前pr的分支上修改并提交即可

@Endures
Copy link
Contributor Author

Endures commented Feb 10, 2022

@liiir1985 修改已提交

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants