diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ValueParameterUnusedIssue.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ValueParameterUnusedIssue.cs index 6381c7b5b2..845b5341f2 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ValueParameterUnusedIssue.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ValueParameterUnusedIssue.cs @@ -66,8 +66,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring // don't warn on empty custom events if (addAccessor.Body.Statements.Count == 0 && removeAccessor.Body.Statements.Count == 0) return; - FindIssuesInNode(addAccessor, addAccessor.Body, "add accessor"); - FindIssuesInNode(removeAccessor, removeAccessor.Body, "remove accessor"); + FindIssuesInAccessor(addAccessor, "add accessor"); + FindIssuesInAccessor(removeAccessor, "remove accessor"); } void FindIssuesInAccessor(Accessor accessor, string accessorName = "setter") diff --git a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs index 2b49e45733..8ac4628b2c 100644 --- a/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs +++ b/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.cs @@ -73,6 +73,7 @@ namespace ICSharpCode.NRefactory.TypeSystem Assert.AreEqual(0, method.Parameters.Count); Assert.AreEqual(0, method.Attributes.Count); Assert.IsTrue(method.HasBody); + Assert.IsNull(method.AccessorOwner); } [Test] @@ -246,6 +247,14 @@ namespace ICSharpCode.NRefactory.TypeSystem Assert.AreEqual(m12, m2); } + [Test] + public void SpecializedMethod_AccessorOwner() + { + // NRefactory bug #143 - Accessor Owner throws null reference exception in some cases now + var method = compilation.FindType(typeof(GenericClass)).GetMethods(m => m.Name == "GetIndex").Single(); + Assert.IsNull(method.AccessorOwner); + } + [Test] public void Specialized_GetIndex_ToMemberReference() { diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedMethod.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedMethod.cs index ca5eee49f2..0721c95362 100644 --- a/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedMethod.cs +++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedMethod.cs @@ -142,7 +142,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation if (result != null) { return result; } else { - result = methodDefinition.AccessorOwner.Specialize(this.Substitution); + var ownerDefinition = methodDefinition.AccessorOwner; + if (ownerDefinition == null) + return null; + result = ownerDefinition.Specialize(this.Substitution); return LazyInit.GetOrSet(ref accessorOwner, result); } }