Skip to content

Commit 0cf6026

Browse files
committed
Merge pull request #1838 from sharwell/fix-1832
Fix SA1009 handling of closing parenthesis followed by pointer dereference
2 parents 736fcd5 + 694aa25 commit 0cf6026

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1009UnitTests.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,17 @@ public async Task TestSpaceMethodCallFollowedByConditionalAccessPropertyGetAsync
324324
await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
325325
}
326326

327+
[Fact]
328+
public async Task TestSpaceMethodCallFollowedByPointerDereferenceAsync()
329+
{
330+
var invalidStatement = @"var o = GetPointer() ->ToString();";
331+
var validStatement = @"var o = GetPointer()->ToString();";
332+
333+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 32);
334+
335+
await this.TestWhitespaceInStatementOrDeclAsync(invalidStatement, validStatement, expected).ConfigureAwait(false);
336+
}
337+
327338
[Fact]
328339
public async Task TestSpaceOperationInDoubleSetOfParenthesisAsync()
329340
{
@@ -820,7 +831,7 @@ private async Task TestWhitespaceInStatementOrDeclAsync(string originalStatement
820831
{{
821832
class Bar
822833
{{
823-
void DoIt()
834+
unsafe void DoIt()
824835
{{
825836
{0}
826837
}}
@@ -835,6 +846,11 @@ Baz GetB()
835846
return null;
836847
}}
837848
849+
unsafe int* GetPointer()
850+
{{
851+
return null;
852+
}}
853+
838854
class Baz
839855
{{
840856
public object this[int i]

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1009ClosingParenthesisMustBeSpacedCorrectly.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ private static void HandleCloseParenToken(SyntaxTreeAnalysisContext context, Syn
128128
break;
129129

130130
case SyntaxKind.DotToken:
131-
// allow a space for this case, but only if the ')' character is the last on the line
131+
case SyntaxKind.MinusGreaterThanToken:
132+
// allow a space for these cases, but only if the ')' character is the last on the line
132133
allowEndOfLine = true;
133134
precedesStickyCharacter = true;
134135
break;

0 commit comments

Comments
 (0)