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 for stackalloc expressions #3256

Merged
merged 2 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,21 @@ public unsafe string TestMethod(int n, byte* a, byte* b)

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

[Fact]
public async Task TestStackAllocExpressionInExpressionAsync()
{
const string testCode = @"public class TestClass
{
public unsafe void TestMethod()
{
var ptr = stackalloc byte[1];
var span = (stackalloc byte[1]);
}
}
";

await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult
internal static Task VerifyCSharpDiagnosticAsync(LanguageVersion? languageVersion, string source, DiagnosticResult expected, CancellationToken cancellationToken)
=> StyleCopDiagnosticVerifier<TAnalyzer>.VerifyCSharpDiagnosticAsync(languageVersion, source, expected, cancellationToken);

internal static Task VerifyCSharpDiagnosticAsync(LanguageVersion? languageVersion, string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
internal static Task VerifyCSharpDiagnosticAsync(LanguageVersion? languageVersion, string source, DiagnosticResult[] expected, CancellationToken cancellationToken = default)
nxtn marked this conversation as resolved.
Show resolved Hide resolved
=> StyleCopDiagnosticVerifier<TAnalyzer>.VerifyCSharpDiagnosticAsync(languageVersion, source, settings: null, expected, cancellationToken);

internal static Task VerifyCSharpDiagnosticAsync(LanguageVersion? languageVersion, string source, string settings, DiagnosticResult[] expected, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ private static void HandleParenthesizedExpression(SyntaxNodeAnalysisContext cont
return;
}

if (node.Expression.IsKind(SyntaxKind.StackAllocArrayCreationExpression)
nxtn marked this conversation as resolved.
Show resolved Hide resolved
&& node.Parent.IsKind(SyntaxKind.EqualsValueClause))
{
return;
}

ReportDiagnostic(context, node);
}
else
Expand Down