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

"Use primary constructor" does not produce a diagnostic for an empty public parameterless constructor #73695

Closed
JakeYallop opened this issue May 24, 2024 · 6 comments · Fixed by #73769
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@JakeYallop
Copy link
Contributor

JakeYallop commented May 24, 2024

Version Used: Compiler version: 4.10.0-3.24230.3 (abc35d6)

Steps to Reproduce:

public class MyClass
{
    public MyClass()
    {
    }
}

Diagnostic Id: IDE0290

Expected Behavior:
IDE0290 "Use primary constructor" diagnostic is raised.

Actual Behavior:
No diagnostic is raised.

Other notes
Just adding a parameter to the constructor:

public class MyClass
{
    public MyClass(string prop)
    {
    }
}

causes the diagnostic be raised.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 24, 2024
@CyrusNajmabadi
Copy link
Member

CyrusNajmabadi commented May 24, 2024

This was intentional, to avoid noisyness. An empty primary constructor doesn't really help at all, since there are no parameters to capture or assign to fields.

@CyrusNajmabadi
Copy link
Member

Note: we can def consider this.

@JakeYallop
Copy link
Contributor Author

Maybe a better fix for this, rather than offering to convert to a primary constructor, should just be to remove the default public parameterless constructor completely?

@CyrusNajmabadi
Copy link
Member

Agreed.

@DoctorKrolic
Copy link
Contributor

An empty primary constructor doesn't really help at all, since there are no parameters to capture or assign to fields.

If such constructor has attributes, it might be benifitial to make it a primary one. A common example pattern is an osbolete MEF import constructors in roslyn

@CyrusNajmabadi
Copy link
Member

@DoctorKrolic i like that idea. let me go do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants