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

Update CA1822 for Primary Constructor Parameters #6801

Closed
333fred opened this issue Jul 25, 2023 · 1 comment
Closed

Update CA1822 for Primary Constructor Parameters #6801

333fred opened this issue Jul 25, 2023 · 1 comment

Comments

@333fred
Copy link
Member

333fred commented Jul 25, 2023

Analyzer

Diagnostic ID: CA1822: Mark members as static

Analyzer source

SDK: Built-in CA analyzers in .NET 8p6 SDK or later

Version: SDK 8.0.0-preview6

Describe the bug

CA1822 needs to be updated to include referencing primary constructor parameters as accessing "instance" state. Right now, it suggests marking members that only access PC parameters as static, which is incorrect. See the screenshots reported here: dotnet/csharplang#7377 (reply in thread)

Steps To Reproduce

  1. Create a new project with .NET 8 and enable analysis.
  2. Create a type with a primary constructor.
  3. Try one of the code samples in the linked comment, such as having an expression-bodied property return a PC parameter.

Expected behavior

No warnings.

Actual behavior

CA1822 is issued.

Additional context

This is a C# 12 feature, may require updating the roslyn reference in tests to use.

@mavasani
Copy link
Contributor

Duplicate of #6573

@mavasani mavasani marked this as a duplicate of #6573 Aug 18, 2023
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

No branches or pull requests

2 participants