Skip to content

Commit

Permalink
Merge pull request #1232 from Noryoko/fix-1230
Browse files Browse the repository at this point in the history
Fix SA1024 incorrectly treating explicit interface implementations as private
  • Loading branch information
sharwell committed Aug 17, 2015
2 parents b121114 + db8f554 commit 72002b5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,32 @@ void IA.TestMethod1() { }
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestExplicitInterfaceFollowedByPrivateStaticAsync()
{
var testCode = @"
public interface TestInterface
{
void SomeMethod();
}
public class TestClass : TestInterface
{
private static void ExampleMethod()
{
}
void TestInterface.SomeMethod()
{
}
}
";

var expected = this.CSharpDiagnostic().WithLocation(13, 24).WithArguments("public", "methods", "private");

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

/// <summary>
/// Verifies that the analyzer will properly handle incomplete members.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,30 @@ public MyClass2()
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestExplicitInterfaceFollowedByPrivateStaticAsync()
{
var testCode = @"
public interface TestInterface
{
void SomeMethod();
}
public class TestClass : TestInterface
{
void TestInterface.SomeMethod()
{
}
private static void ExampleMethod()
{
}
}
";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that the analyzer will properly incomplete members.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ private static void HandleMemberList(SyntaxNodeAnalysisContext context, SyntaxLi
var currentMemberStatic = modifiers.Any(SyntaxKind.StaticKeyword);
var currentMemberConst = modifiers.Any(SyntaxKind.ConstKeyword);
AccessLevel currentAccessLevel;
if (currentMemberStatic && currentSyntaxKind == SyntaxKind.ConstructorDeclaration)
if ((currentSyntaxKind == SyntaxKind.ConstructorDeclaration && modifiers.Any(SyntaxKind.StaticKeyword))
|| (currentSyntaxKind == SyntaxKind.MethodDeclaration && (member as MethodDeclarationSyntax)?.ExplicitInterfaceSpecifier != null)
|| (currentSyntaxKind == SyntaxKind.PropertyDeclaration && (member as PropertyDeclarationSyntax)?.ExplicitInterfaceSpecifier != null)
|| (currentSyntaxKind == SyntaxKind.IndexerDeclaration && (member as IndexerDeclarationSyntax)?.ExplicitInterfaceSpecifier != null))
{
currentAccessLevel = AccessLevel.Public;
}
Expand Down

0 comments on commit 72002b5

Please sign in to comment.