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

Primary constructor parameter gives incorrect "could be static" warning #6573

Closed
KathleenDollard opened this issue Apr 6, 2023 · 1 comment · Fixed by #6677
Closed

Primary constructor parameter gives incorrect "could be static" warning #6573

KathleenDollard opened this issue Apr 6, 2023 · 1 comment · Fixed by #6677
Labels
False_Positive A diagnostic is reported for non-problematic case untriaged

Comments

@KathleenDollard
Copy link

Version Used: Version 17.7.0 Preview 1.0 [33603.545.main]

Steps to Reproduce:

  1. Compiler this code:
using System.Collections.Generic; 
using System.Linq;

public class Student(int id, string name, IEnumerable<decimal> grades)
    {
        public Student(int id, string name) : this(id, name, new List<decimal>()) { }
        public int Id => id;
        public string Name { get; set; } = name.Trim();
        public decimal GPA => grades.Any() ? grades.Average() : 4.0m;
    }
  1. Check for warnings

Diagnostic Id: CA182

Expected Behavior: Does not offer to change to static.

Actual Behavior: For two of the three primary ctor parameters in the example, an offer is made to change to static. It is not clear why 2 of the 3.

primaryctorbug1

@CyrusNajmabadi
Copy link
Member

This is blocking hte ability for Roslyn to use primary constructors itself. Can you guys please prioritize this?

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 untriaged
Projects
None yet
3 participants