Skip to content

Commit

Permalink
Fix invalid cast in SA1313
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Sep 10, 2015
1 parent 526ebb0 commit b1c8eac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,27 @@ public override void Method(int Param1, int param2, int Other)
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// This is a regression test for DotNetAnalyzers/StyleCopAnalyzers#1442:
/// https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1442
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
[Fact]
public async Task TestSimpleLambaExpressionAsync()
{
var testCode = @"public class TypeName
{
public void MethodName()
{
System.Action<int> action = Ignored => { };
}
}";

DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("Ignored").WithLocation(5, 37);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
{
yield return new SA1313ParameterNamesMustBeginWithLowerCaseLetter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ private static void HandleParameterSyntax(SyntaxNodeAnalysisContext context)

private static bool NameMatchesAbstraction(ParameterSyntax syntax, SemanticModel semanticModel)
{
var parameterList = (ParameterListSyntax)syntax.Parent;
var parameterList = syntax.Parent as ParameterListSyntax;
if (parameterList == null)
{
// This occurs for simple lambda expressions (without parentheses)
return false;
}

var index = parameterList.Parameters.IndexOf(syntax);
var declaringMember = syntax.Parent.Parent;

Expand Down

0 comments on commit b1c8eac

Please sign in to comment.