Browse Source

Fix #958: Invalid cast in generic class for abstract base call

pull/925/merge
Siegfried Pammer 8 years ago
parent
commit
fbe4a1b2db
  1. 26
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Generics.cs
  2. 2
      ICSharpCode.Decompiler/NRExtensions.cs

26
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Generics.cs

@ -57,11 +57,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
} }
} }
public class BaseClass public abstract class BaseClass
{ {
protected abstract void Method1<T>(T test);
} }
public class DerivedClass : BaseClass public class DerivedClass : BaseClass
{ {
protected override void Method1<T>(T test) { }
private void Method2()
{
this.Method1(0);
}
}
#region Issue 958 - Invalid cast in generic class for abstract base call
internal abstract class BaseClass<T>
{
protected abstract void Method1();
}
internal class DerivedClass<T> : BaseClass<T>
{
protected override void Method1() { }
private void Method2()
{
this.Method1();
}
} }
#endregion
} }

2
ICSharpCode.Decompiler/NRExtensions.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.Decompiler
if (decompilationContext.CurrentTypeDefinition != null) if (decompilationContext.CurrentTypeDefinition != null)
classTypeParameters = decompilationContext.CurrentTypeDefinition.TypeArguments; classTypeParameters = decompilationContext.CurrentTypeDefinition.TypeArguments;
IMethod method = decompilationContext.CurrentMember as IMethod; IMethod method = decompilationContext.CurrentMember as IMethod;
if (method != null) if (method != null && method.TypeParameters.Count > 0)
methodTypeParameters = method.TypeArguments; methodTypeParameters = method.TypeArguments;
if (typeSystem is SpecializingDecompilerTypeSystem) if (typeSystem is SpecializingDecompilerTypeSystem)
typeSystem = ((SpecializingDecompilerTypeSystem)typeSystem).Context; typeSystem = ((SpecializingDecompilerTypeSystem)typeSystem).Context;

Loading…
Cancel
Save