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

false-positive for CA1810 #5784

Closed
elachlan opened this issue Jan 7, 2022 · 4 comments
Closed

false-positive for CA1810 #5784

elachlan opened this issue Jan 7, 2022 · 4 comments
Labels
False_Positive A diagnostic is reported for non-problematic case Resolution-By Design

Comments

@elachlan
Copy link

elachlan commented Jan 7, 2022

Analyzer

Diagnostic ID: CA1810: Initialize reference type static fields inline

Analyzer source

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

Version: SDK 6.0.100

Describe the bug

False Positive. Static constructor sets static class fields.
(https://github.com/dotnet/msbuild/blob/797fd829a374a880f63fd4eea4ea6990404c48f4/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs#L39-L49)

Steps To Reproduce

Run the analyzer on the above mentioned code.

Additional context

Using the analyzer on msbuild the related issue is #7179

@Evangelink Evangelink added False_Positive A diagnostic is reported for non-problematic case help wanted The issue is up-for-grabs, and can be claimed by commenting Verified labels Jan 24, 2022
@sharwell
Copy link
Member

I'm not certain this is a false positive. Even though the types are defined in a different class, they can still be initialized at a declaration site instead of in this static constructor.

@Evangelink Evangelink added Needs-Review and removed help wanted The issue is up-for-grabs, and can be claimed by commenting labels Jan 25, 2022
@elachlan
Copy link
Author

I am closing the issue, because I think the analyzer pointing this out helps highlight code that can be better optimized. Which is the point of the Analyzer.

@Evangelink
Copy link
Member

@sharwell Let me know when you are done with your investigation.

@Evangelink
Copy link
Member

@sharwell Let me know if you want me to close the PR or if you feel like there would be some value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False_Positive A diagnostic is reported for non-problematic case Resolution-By Design
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants