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

CA1515: false positive with delegates #7464

Open
pcf0 opened this issue Nov 2, 2024 · 2 comments
Open

CA1515: false positive with delegates #7464

pcf0 opened this issue Nov 2, 2024 · 2 comments

Comments

@pcf0
Copy link

pcf0 commented Nov 2, 2024

Analyzer

Diagnostic ID: CA1515: Consider making public types internal

Analyzer source

SDK: Built-in CA analyzers in .NET 9 SDK or later

Version: SDK 9.0.100-rc.2.24474.11

OR

NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers

Version: 9.0.0-preview.24454.1

Describe the bug

A public delegate is defined within an internal class. CA1859 is generated for the delegate.

Steps To Reproduce

  1. Create an executable project, e.g. a console project.
  2. Create a internal class with a public delegate
internal class Class1
{
    public delegate void SomeDelegate();
}

Expected behavior

No errors reported

Actual behavior

Error reported:
Class1.cs(3,26): error CA1515: Because an application's API isn't typically referenced from outside the assembly, types can be made internal (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1515)

Additional context

@invino4
Copy link

invino4 commented Nov 14, 2024

This false positive seems to happen for any public nested type of an otherwise internal type. The analyzer SHOULD be checking if the target type is "effectively public" rather than marked public.

@Thomas-Shephard
Copy link

Thomas-Shephard commented Nov 27, 2024

I did create a merge request that checks if the type/delegate/enum is externally accessible instead of public.

However, from reading through the docs it isn't quite clear whether this is intended but some of the tests for this functionality imply that it is intended...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants