Browse Source

Fix missing 'base.' qualifier on non-virtual call to virtual base method.

pull/1129/head
Daniel Grunwald 7 years ago
parent
commit
80e191ae03
  1. 22
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/MemberLookup.cs
  2. 2
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs
  3. 4
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs

22
ICSharpCode.Decompiler.Tests/TestCases/Correctness/MemberLookup.cs

@ -29,6 +29,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -29,6 +29,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine((new Child1() as Base1).Field);
Child1.Test();
delegateConstruction();
new Child2b().CallTestMethod();
return 0;
}
@ -82,6 +83,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -82,6 +83,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
child.TestMethod();
Console.WriteLine("Child1.TestMethod()");
Console.WriteLine("Property = " + Property + " " + base.Property);
Console.WriteLine("Field = " + Field);
Console.WriteLine("base.Field = " + base.Field);
}
new public void TestAction()
@ -97,5 +100,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -97,5 +100,24 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
}
}
}
class Child2 : Base1
{
public void CallTestMethod()
{
Console.WriteLine("Child2 calling this.TestMethod():");
this.TestMethod();
Console.WriteLine("Child2 calling base.TestMethod():");
base.TestMethod();
}
}
class Child2b : Child2
{
protected override void TestMethod()
{
Console.WriteLine("Child2b.TestMethod");
}
}
}
}

2
ICSharpCode.Decompiler.Tests/TestCases/Pretty/FixProxyCalls.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty @@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
{
protected internal IEnumerable<string> Test2(string test)
{
yield return Test(test);
yield return base.Test(test);
}
}

4
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -209,8 +209,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -209,8 +209,10 @@ namespace ICSharpCode.Decompiler.CSharp
} else {
if (method.IsStatic)
requireTarget = !expressionBuilder.IsCurrentOrContainingType(method.DeclaringTypeDefinition) || method.Name == ".cctor";
else if (target.Expression is BaseReferenceExpression)
requireTarget = (callOpCode != OpCode.CallVirt && method.IsVirtual);
else
requireTarget = !(target.Expression is ThisReferenceExpression || target.Expression is BaseReferenceExpression) || method.Name == ".ctor";
requireTarget = !(target.Expression is ThisReferenceExpression) || method.Name == ".ctor";
}
bool targetCasted = false;
bool argumentsCasted = false;

Loading…
Cancel
Save