Browse Source

Fix distinction between 'this' and 'base' in generic classes.

pull/70/head
Daniel Grunwald 15 years ago
parent
commit
9fab4e4ac0
  1. 2
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 30
      ICSharpCode.Decompiler/Tests/Generics.cs
  3. 1
      ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj

2
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -638,7 +638,7 @@ namespace Decompiler @@ -638,7 +638,7 @@ namespace Decompiler
}
if (target is ThisReferenceExpression && !isVirtual) {
// a non-virtual call on "this" might be a "base"-call.
if (cecilMethod.DeclaringType != methodDef.DeclaringType) {
if ((cecilMethod.DeclaringType.IsGenericInstance ? cecilMethod.DeclaringType.GetElementType() : cecilMethod.DeclaringType) != methodDef.DeclaringType) {
// If we're not calling a method in the current class; we must be calling one in the base class.
target = new BaseReferenceExpression();
}

30
ICSharpCode.Decompiler/Tests/Generics.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
public static class Generics
{
class MyArray<T>
{
private T[] arr;
public MyArray(int capacity)
{
this.arr = new T[capacity];
}
public void Size(int capacity)
{
Array.Resize(ref this.arr, capacity);
}
public void Grow(int capacity)
{
if (capacity >= this.arr.Length)
{
this.Size(capacity);
}
}
}
}

1
ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj

@ -51,6 +51,7 @@ @@ -51,6 +51,7 @@
<Compile Include="ArrayInitializers.cs" />
<Compile Include="DelegateConstruction.cs" />
<Compile Include="ExceptionHandling.cs" />
<Compile Include="Generics.cs" />
<Compile Include="MultidimensionalArray.cs" />
<Compile Include="Loops.cs" />
<Compile Include="PropertiesAndEvents.cs" />

Loading…
Cancel
Save