From fbe4a1b2dba68e5056671006db63a884c1b6fe8f Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 1 Nov 2017 13:54:19 +0100 Subject: [PATCH] Fix #958: Invalid cast in generic class for abstract base call --- .../TestCases/Correctness/Generics.cs | 26 ++++++++++++++++++- ICSharpCode.Decompiler/NRExtensions.cs | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Generics.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Generics.cs index 0ff0b26a5..df65be4f2 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Generics.cs +++ b/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 test); } public class DerivedClass : BaseClass { + protected override void Method1(T test) { } + + private void Method2() + { + this.Method1(0); + } + } + + #region Issue 958 - Invalid cast in generic class for abstract base call + internal abstract class BaseClass + { + protected abstract void Method1(); + } + + internal class DerivedClass : BaseClass + { + protected override void Method1() { } + + private void Method2() + { + this.Method1(); + } } + #endregion } diff --git a/ICSharpCode.Decompiler/NRExtensions.cs b/ICSharpCode.Decompiler/NRExtensions.cs index 4e72c08ab..3f0a5c38a 100644 --- a/ICSharpCode.Decompiler/NRExtensions.cs +++ b/ICSharpCode.Decompiler/NRExtensions.cs @@ -31,7 +31,7 @@ namespace ICSharpCode.Decompiler if (decompilationContext.CurrentTypeDefinition != null) classTypeParameters = decompilationContext.CurrentTypeDefinition.TypeArguments; IMethod method = decompilationContext.CurrentMember as IMethod; - if (method != null) + if (method != null && method.TypeParameters.Count > 0) methodTypeParameters = method.TypeArguments; if (typeSystem is SpecializingDecompilerTypeSystem) typeSystem = ((SpecializingDecompilerTypeSystem)typeSystem).Context;