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

CA1000 hasn't been reconsidered with static abstracts in mind #7126

Closed
RenderMichael opened this issue Jan 9, 2024 · 4 comments · Fixed by #7142
Closed

CA1000 hasn't been reconsidered with static abstracts in mind #7126

RenderMichael opened this issue Jan 9, 2024 · 4 comments · Fixed by #7142
Assignees
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers False_Positive A diagnostic is reported for non-problematic case help wanted The issue is up-for-grabs, and can be claimed by commenting
Milestone

Comments

@RenderMichael
Copy link
Contributor

RenderMichael commented Jan 9, 2024

Analyzer

Diagnostic ID: CA1000: Do not declare static members on generic types

Analyzer source

.NET 8.0.100 SDK

The pattern adopted for generic math in .NET 7, known as "Curiously recurring template pattern", violates this rule. Of course a rule like this one isn't enabled in the runtime repo, but when I tried to do the same I got this diagnostic pop up.

Steps To Reproduce

Using .NET >=7:

public interface IConfigurationFileProvider<TConfiguration>
{
    public static abstract TConfiguration FromFile(string path);
}

Expected behavior

When the member is abstract, this diagnostic should not fire.

Actual behavior

This diagnostic fires.

Additional Context

The above repro is a minimal repro, but this diagnostic still fires when using the recursive pattern:

public interface IConfigurationFileProvider<TConfiguration>
    where TConfiguration : IConfigurationFileProvider<TConfiguration>
{
    public static abstract TConfiguration FromFile(string path);
}
@mavasani
Copy link
Contributor

Sounds reasonable to me. @buyaa-n?

@mavasani mavasani added Needs-Review Area-Microsoft.CodeAnalysis.NetAnalyzers False_Positive A diagnostic is reported for non-problematic case labels Jan 10, 2024
@mavasani mavasani added this to the Unknown milestone Jan 10, 2024
@buyaa-n
Copy link
Contributor

buyaa-n commented Jan 12, 2024

Sounds good to me too

@buyaa-n buyaa-n added help wanted The issue is up-for-grabs, and can be claimed by commenting and removed Needs-Review labels Jan 12, 2024
@RenderMichael
Copy link
Contributor Author

Can this bug be assigned to me? It looks like a straightforward fix.

@RenderMichael
Copy link
Contributor Author

Opened PR #7142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers False_Positive A diagnostic is reported for non-problematic case help wanted The issue is up-for-grabs, and can be claimed by commenting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants