Skip to content

Commit

Permalink
Merge pull request #3733 from bjornhellander/feature/sa1119-switch-ex…
Browse files Browse the repository at this point in the history
…pr-call

Update SA1119 to allow parenthesized switch expressions followed by an invocation
  • Loading branch information
sharwell authored Nov 28, 2023
2 parents 081e2d0 + 8dd785a commit 73f64f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,25 @@ public unsafe string TestMethod(int n, byte* a, byte* b)
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3730, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3730")]
public async Task TestSwitchExpressionFollowedByInvocationAsync()
{
string testCode = @"
using System;
public class Foo
{
public string TestMethod(int n, Func<string> a, Func<string> b)
{
return (n switch { 1 => a, 2 => b })();
}
}
";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestStackAllocExpressionInExpressionAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ private static bool IsSwitchOrWithExpressionWithRequiredParentheses(Parenthesize
MemberAccessExpressionSyntax memberAccessExpression => memberAccessExpression.Expression == outerExpression,
ConditionalAccessExpressionSyntax conditionalAccessExpression => conditionalAccessExpression.Expression == outerExpression,
ElementAccessExpressionSyntax elementAccessExpression => elementAccessExpression.Expression == outerExpression,
InvocationExpressionSyntax invocationExpression => invocationExpression.Expression == outerExpression,
_ => false,
};
}
Expand Down

0 comments on commit 73f64f7

Please sign in to comment.