Skip to content

Commit 5074b22

Browse files
committed
Merge pull request #1460 from sharwell/fix-1457
Fix handling of '*' followed by '*' or ')'
2 parents f5b914d + 5282df4 commit 5074b22

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1023UnitTests.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ unsafe void TestMethod()
3333
*x += 1;
3434
int*[] y;
3535
y = new int*[5];
36+
37+
// The following cases are all regression tests for DotNetAnalyzers/StyleCopAnalyzers#1457
38+
x = (int*)null;
39+
x = *(int**)null;
40+
var t = typeof(char*);
41+
t = typeof(char**);
42+
var d1 = default(char*);
43+
var d2 = default(char**);
44+
a = *x * *x;
3645
}
3746
}
3847
";
@@ -60,6 +69,15 @@ unsafe void TestMethod()
6069
* z = x;
6170
a = *
6271
x;
72+
73+
// The following cases are all regression tests for DotNetAnalyzers/StyleCopAnalyzers#1457
74+
x = (int * )null;
75+
x = * (int* * )null;
76+
var t = typeof(char *);
77+
t = typeof(char* *);
78+
var d1 = default(char* );
79+
var d2 = default(char** );
80+
a = * x** x;
6381
}
6482
}
6583
";
@@ -75,6 +93,15 @@ unsafe void TestMethod()
7593
y = new int*[5];
7694
int* z = x;
7795
a = *x;
96+
97+
// The following cases are all regression tests for DotNetAnalyzers/StyleCopAnalyzers#1457
98+
x = (int*)null;
99+
x = *(int**)null;
100+
var t = typeof(char*);
101+
t = typeof(char**);
102+
var d1 = default(char*);
103+
var d2 = default(char**);
104+
a = *x**x;
78105
}
79106
}
80107
";
@@ -87,7 +114,20 @@ unsafe void TestMethod()
87114
this.CSharpDiagnostic().WithLocation(9, 21).WithArguments("not be preceded by a space"),
88115
this.CSharpDiagnostic().WithLocation(9, 21).WithArguments("not be followed by a space"),
89116
this.CSharpDiagnostic().WithLocation(11, 0).WithArguments("not appear at the beginning of a line"),
90-
this.CSharpDiagnostic().WithLocation(12, 13).WithArguments("not appear at the end of a line")
117+
this.CSharpDiagnostic().WithLocation(12, 13).WithArguments("not appear at the end of a line"),
118+
this.CSharpDiagnostic().WithLocation(16, 18).WithArguments("not be preceded by a space"),
119+
this.CSharpDiagnostic().WithLocation(16, 18).WithArguments("not be followed by a space"),
120+
this.CSharpDiagnostic().WithLocation(17, 13).WithArguments("not be followed by a space"),
121+
this.CSharpDiagnostic().WithLocation(17, 19).WithArguments("not be followed by a space"),
122+
this.CSharpDiagnostic().WithLocation(17, 21).WithArguments("not be preceded by a space"),
123+
this.CSharpDiagnostic().WithLocation(17, 21).WithArguments("not be followed by a space"),
124+
this.CSharpDiagnostic().WithLocation(18, 29).WithArguments("not be preceded by a space"),
125+
this.CSharpDiagnostic().WithLocation(19, 24).WithArguments("not be followed by a space"),
126+
this.CSharpDiagnostic().WithLocation(19, 26).WithArguments("not be preceded by a space"),
127+
this.CSharpDiagnostic().WithLocation(20, 30).WithArguments("not be followed by a space"),
128+
this.CSharpDiagnostic().WithLocation(21, 31).WithArguments("not be followed by a space"),
129+
this.CSharpDiagnostic().WithLocation(22, 13).WithArguments("not be followed by a space"),
130+
this.CSharpDiagnostic().WithLocation(22, 17).WithArguments("not be followed by a space"),
91131
};
92132

93133
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ private static void HandleAsteriskToken(SyntaxTreeAnalysisContext context, Synta
110110
{
111111
case SyntaxKind.OpenBracketToken:
112112
case SyntaxKind.OpenParenToken:
113+
case SyntaxKind.CloseParenToken:
114+
case SyntaxKind.AsteriskToken:
113115
allowTrailingSpace = false;
114116
break;
117+
115118
default:
116119
allowTrailingSpace = true;
117120
break;

0 commit comments

Comments
 (0)