Skip to content

Commit

Permalink
Fixed Ourpalm#316
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Apr 1, 2020
1 parent ef7a64b commit 5a30a15
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
15 changes: 13 additions & 2 deletions ILRuntime/CLR/TypeSystem/ILType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public bool IsEnum
}
}

string fullName;
string fullName, fullNameForNested;
public string FullName
{
get
Expand All @@ -473,6 +473,12 @@ public string FullName
}
else
fullName = typeRef.FullName;
if (typeRef.IsNested)
{
fullNameForNested = fullName.Replace("/", ".");
}
else
fullNameForNested = fullName;
}
return fullName;
}
Expand Down Expand Up @@ -706,7 +712,12 @@ public IMethod GetVirtualMethod(IMethod method)
var m = GetMethod(method.Name, method.Parameters, genericArguments, method.ReturnType, true);
if (m == null && method.DeclearingType.IsInterface)
{
m = GetMethod(string.Format("{0}.{1}", method.DeclearingType.FullName, method.Name), method.Parameters, genericArguments, method.ReturnType, true);
if(method.DeclearingType is ILType iltype)
{
m = GetMethod(string.Format("{0}.{1}", iltype.fullNameForNested, method.Name), method.Parameters, genericArguments, method.ReturnType, true);
}
else
m = GetMethod(string.Format("{0}.{1}", method.DeclearingType.FullName, method.Name), method.Parameters, genericArguments, method.ReturnType, true);
}

if (m == null)
Expand Down
34 changes: 33 additions & 1 deletion TestCases/InheritanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,33 @@ namespace TestCases
void TestAbstract();
void TestField();
}

public class InheritanceTest
{
interface ITest
{
void TestMethod();
}

public class TestA : ITest
{
void ITest.TestMethod()//显式实现接口方法
{
Console.WriteLine("方法A");
}
}

public class TestB : ITest
{
void ITest.TestMethod()//显式实现接口方法
{
Console.WriteLine("方法A");
}

public void TestMethod()
{
Console.WriteLine("方法B");
}
}
public static void InheritanceTest01()
{
TestCls cls = new TestCls();
Expand Down Expand Up @@ -55,6 +79,14 @@ public static void InheritanceTest_Interface()
cls3.TestField();
}

public static void InheritanceTest_Interface2()
{
ITest b = new TestB();
b.TestMethod();//此处输入结果为 方法B
ITest a = new TestA();
a.TestMethod();//发生异常
}

static void Test01Sub(ClassInheritanceTest cls)
{
Console.WriteLine("Test invoking from base type...");
Expand Down

0 comments on commit 5a30a15

Please sign in to comment.