Skip to content

Commit 060397f

Browse files
authored
Merge pull request #2579 from vweijsters/fix-2564
Fixed false positive in SA1011 for array index followed by pointer de…
2 parents d29958f + c9e33d9 commit 060397f

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1011UnitTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,26 @@ void Method()
312312
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
313313
}
314314

315+
[Fact]
316+
[WorkItem(2564, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2564")]
317+
public async Task TestArrayElementPointerDeferenceAsync()
318+
{
319+
var testCode = @"public class TestClass
320+
{
321+
public unsafe string TestMethod(int[] a)
322+
{
323+
fixed (int* p = a)
324+
{
325+
int*[] xx = new[] { p };
326+
return xx[0]->ToString(""n2"");
327+
}
328+
}
329+
}
330+
";
331+
332+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
333+
}
334+
315335
/// <inheritdoc/>
316336
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
317337
{

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1011ClosingSquareBracketsMustBeSpacedCorrectly.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ private static void HandleCloseBracketToken(SyntaxTreeAnalysisContext context, S
103103
case SyntaxKind.DotToken:
104104
case SyntaxKind.OpenBracketToken:
105105
case SyntaxKind.CloseParenToken:
106+
case SyntaxKind.MinusGreaterThanToken:
106107
precedesSpecialCharacter = true;
107108
break;
108109
case SyntaxKind.PlusPlusToken:

0 commit comments

Comments
 (0)