diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/CompilerErrors/CS0127ReturnMustNotBeFollowedByAnyExpression.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/CompilerErrors/CS0127ReturnMustNotBeFollowedByAnyExpression.cs index 282ae6ada3..74963978cf 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/CompilerErrors/CS0127ReturnMustNotBeFollowedByAnyExpression.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/CompilerErrors/CS0127ReturnMustNotBeFollowedByAnyExpression.cs @@ -1,4 +1,4 @@ -// +// // CS0127ReturnMustNotBeFollowedByAnyExpression.cs // // Author: @@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring class GatherVisitor : GatherVisitorBase { - MethodDeclaration currentMethod; + string currentMethodName; public GatherVisitor (BaseRefactoringContext ctx) : base (ctx) { @@ -54,10 +54,22 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring var primitiveType = methodDeclaration.ReturnType as PrimitiveType; if (primitiveType == null || primitiveType.Keyword != "void") return; - currentMethod = methodDeclaration; + currentMethodName = methodDeclaration.Name; base.VisitMethodDeclaration(methodDeclaration); } + public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) + { + currentMethodName = constructorDeclaration.Name; + base.VisitConstructorDeclaration(constructorDeclaration); + } + + public override void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration) + { + currentMethodName = "~" + destructorDeclaration.Name; + base.VisitDestructorDeclaration(destructorDeclaration); + } + public override void VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration) { } @@ -87,7 +99,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring if (!returnStatement.Expression.IsNull) { AddIssue( returnStatement, - string.Format (ctx.TranslateString("`{0}': A return keyword must not be followed by any expression when method returns void"), currentMethod.Name), + string.Format (ctx.TranslateString("`{0}': A return keyword must not be followed by any expression when method returns void"), currentMethodName), new CodeAction ( ctx.TranslateString("Remove returned expression"), script => { diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/CS0127ReturnMustNotBeFollowedByAnyExpressionTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/CS0127ReturnMustNotBeFollowedByAnyExpressionTests.cs index 293f204b21..1b31aff653 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/CS0127ReturnMustNotBeFollowedByAnyExpressionTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/CS0127ReturnMustNotBeFollowedByAnyExpressionTests.cs @@ -1,4 +1,4 @@ -// +// // CS0127ReturnMustNotBeFollowedByAnyExpressionTests.cs // // Author: @@ -158,7 +158,37 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues Assert.AreEqual (0, issues.Count); } - + [Test] + public void TestConstructor () + { + var input = @"class Foo +{ + Foo () + { + return 1; + } +}"; + + TestRefactoringContext context; + var issues = GetIssues (new CS0127ReturnMustNotBeFollowedByAnyExpression (), input, out context); + Assert.AreEqual (1, issues.Count); + } + + [Test] + public void TestDestructor () + { + var input = @"class Foo +{ + ~Foo () + { + return 1; + } +}"; + + TestRefactoringContext context; + var issues = GetIssues (new CS0127ReturnMustNotBeFollowedByAnyExpression (), input, out context); + Assert.AreEqual (1, issues.Count); + } } }