Skip to content

Commit c3c1e4d

Browse files
committed
Merge pull request #1740 from bexxx/fix1507
Fix for 1507
2 parents 1204682 + 9e25506 commit c3c1e4d

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1202UnitTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,43 @@ public string
955955
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
956956
}
957957

958+
/// <summary>
959+
/// Verifies that the analyzer will properly handle incomplete members.
960+
/// </summary>
961+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
962+
[Fact]
963+
public async Task Issue1507RegressionAsync()
964+
{
965+
string testCode = @"public class OuterType
966+
{
967+
private string Test;
968+
private string
969+
public string
970+
}
971+
";
972+
973+
// We don't care about the syntax errors.
974+
var expected = new[]
975+
{
976+
new DiagnosticResult
977+
{
978+
Id = "CS1585",
979+
Message = "Member modifier 'public' must precede the member type and name",
980+
Severity = DiagnosticSeverity.Error,
981+
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 5, 5) }
982+
},
983+
new DiagnosticResult
984+
{
985+
Id = "CS1519",
986+
Message = "Invalid token '}' in class, struct, or interface member declaration",
987+
Severity = DiagnosticSeverity.Error,
988+
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 6, 1) }
989+
}
990+
};
991+
992+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
993+
}
994+
958995
/// <inheritdoc/>
959996
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
960997
{

StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1202ElementsMustBeOrderedByAccess.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ private static void HandleMemberList(SyntaxNodeAnalysisContext context, SyntaxLi
122122
{
123123
var currentSyntaxKind = member.Kind();
124124
currentSyntaxKind = currentSyntaxKind == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : currentSyntaxKind;
125+
126+
// if the SyntaxKind of this member (e.g. SyntaxKind.IncompleteMember) will not
127+
// be handled, skip early.
128+
if (!MemberNames.ContainsKey(currentSyntaxKind))
129+
{
130+
continue;
131+
}
132+
125133
AccessLevel currentAccessLevel;
126134
var modifiers = member.GetModifiers();
127135
if ((currentSyntaxKind == SyntaxKind.ConstructorDeclaration && modifiers.Any(SyntaxKind.StaticKeyword))

0 commit comments

Comments
 (0)