From 19363563d81ffa67eba7a522338c6a3c66ebcaab Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 30 Oct 2015 22:52:35 +0100 Subject: [PATCH] fix bug in RECS0099 --- .../Custom/ParameterOnlyAssignedAnalyzer.cs | 8 ++-- .../Diagnostics/ParameterOnlyAssignedTests.cs | 43 +++++++++++-------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/RefactoringEssentials/CSharp/Diagnostics/Custom/ParameterOnlyAssignedAnalyzer.cs b/RefactoringEssentials/CSharp/Diagnostics/Custom/ParameterOnlyAssignedAnalyzer.cs index 3fd56a85..f0203a38 100644 --- a/RefactoringEssentials/CSharp/Diagnostics/Custom/ParameterOnlyAssignedAnalyzer.cs +++ b/RefactoringEssentials/CSharp/Diagnostics/Custom/ParameterOnlyAssignedAnalyzer.cs @@ -55,7 +55,7 @@ private static bool TryGetDiagnostic(SyntaxNodeAnalysisContext nodeContext, out return false; var method = parameter.Parent.Parent as MethodDeclarationSyntax; - if ((method == null) || (method.Body == null)) + if (method == null || method.Body == null) return false; var dataFlow = nodeContext.SemanticModel.AnalyzeDataFlow(method.Body); @@ -66,8 +66,10 @@ private static bool TryGetDiagnostic(SyntaxNodeAnalysisContext nodeContext, out { var expression = statement as ExpressionStatementSyntax; var assignment = expression?.Expression as AssignmentExpressionSyntax; - if (assignment != null && - (nodeContext.SemanticModel.GetSymbolInfo(assignment.Left).Symbol as IParameterSymbol)!= null) + if (assignment == null) + continue; + var symbol = nodeContext.SemanticModel.GetSymbolInfo(assignment.Left).Symbol as IParameterSymbol; + if (localParamSymbol.Equals(symbol)) { diagnostic = Diagnostic.Create(descriptor, assignment.GetLocation()); return true; diff --git a/Tests/CSharp/Diagnostics/ParameterOnlyAssignedTests.cs b/Tests/CSharp/Diagnostics/ParameterOnlyAssignedTests.cs index 13767b07..83db6924 100644 --- a/Tests/CSharp/Diagnostics/ParameterOnlyAssignedTests.cs +++ b/Tests/CSharp/Diagnostics/ParameterOnlyAssignedTests.cs @@ -9,29 +9,26 @@ public class ParameterOnlyAssignedTests : CSharpDiagnosticTestBase [Test] public void TestUnusedValue() { - var input = @" + Analyze(@" class TestClass { void TestMethod(int i) { $i = 1$; } -}"; - - var output = @" +}", @" class TestClass { void TestMethod(int i) { } -}"; - Analyze(input,output); +}"); } [Test] public void TestUsedValue() { - var input = @" + Analyze(@" class TestClass { int TestMethod(int i) @@ -39,36 +36,48 @@ int TestMethod(int i) i = 1; return i; } -}"; - Analyze(input); +}"); } [Test] - public void TestOutParametr() + public void TestOutParameter() { - var input = @" + Analyze(@" class TestClass { void TestMethod(out int i) { i = 1; } -}"; - Analyze(input); +}"); } [Test] - public void TestRefParametr() + public void TestRefParameter() { - var input = @" + Analyze(@" class TestClass { void TestMethod(ref int i) { i = 1; } -}"; - Analyze(input); +}"); + } + + [Test] + public void TestMultipleParameters() + { + Analyze(@" +class TestClass +{ + public static void TestMethod(out T argument, ref T2 argument2, T3 argument3) where T : class where T2 : struct + { + argument = null; + argument2 = default(T2); + $argument3 = default(T3)$; + } +}"); } } }