Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SA1119 to allow parenthesized switch expressions followed by an invocation #3733

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -230,6 +230,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