Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't report CA2257 on nested types #7157

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static void AnalyzeType(SymbolAnalysisContext context, INamedTypeSymbol

foreach (var member in targetType.GetMembers())
{
if (!member.IsImplementationOfAnyExplicitInterfaceMember() && !member.IsStatic)
if (!member.IsImplementationOfAnyExplicitInterfaceMember() && !member.IsStatic && !member.IsType())
{
// We don't want to emit diagnostics when the member is an accessor method.
if (member is not IMethodSymbol { AssociatedSymbol: IPropertySymbol or IEventSymbol })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,31 @@ static void I.M()
await VerifyCSCodeFixAsync(source, fixedSource, CSharp.LanguageVersion.Preview, ReferenceAssemblies.Net.Net60);
}

[Fact]
[WorkItem(7106, "htpts://github.com/dotnet/roslyn-analyzers/issues/7106")]
public async Task DynamicInterfaceCastableImplementation_NonStatic_NestedType()
{
string source = @"
using System.Runtime.InteropServices;

public interface IMyInterface
{
void M();
}

[DynamicInterfaceCastableImplementation]
internal interface IImpl : IMyInterface
{
internal class C { }

void IMyInterface.M()
{
}
}
";
await VerifyCSAnalyzerAsync(source);
}

private static Task VerifyCSAnalyzerAsync(string source)
{
return VerifyCSCodeFixAsync(source, source);
Expand Down