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

CA1801 false positive on record parameter if any parameter has a default value #4462

Closed
thomaslevesque opened this issue Nov 26, 2020 · 4 comments · Fixed by #4499
Closed
Labels
False_Positive A diagnostic is reported for non-problematic case help wanted The issue is up-for-grabs, and can be claimed by commenting

Comments

@thomaslevesque
Copy link
Member

Analyzer

Diagnostic ID: CA1801: Review unused parameters

Analyzer source

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

Version: SDK 5.0.100-rc.2

Describe the bug

If any parameter of a positional record has a default value, CA1801 is reported on all parameters.

Steps To Reproduce

Write this code:

public record Foo(string Name, int Age = 0);

Expected behavior

No warning

Actual behavior

CA1801 is reported on all parameters:

Parameter Name of method .ctor is never used. Remove the parameter or use it in the method body.
Parameter Age of method .ctor is never used. Remove the parameter or use it in the method body.

Additional context

Looks very similar to #4397

@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 Nov 26, 2020
@Evangelink
Copy link
Member

I confirm that I can reproduce the issue.

Regarding how to fix the issue, I am not sure what to do. I think there is a bug (or at least something missing) on roslyn because the property IsImplicitlyDeclared returns false while IMO it should return true.

@mavasani let me know if I am missing something.

@Youssef1313
Copy link
Member

Youssef1313 commented Nov 27, 2020

@Evangelink See similar discussion in dotnet/roslyn#48193 and also in dotnet/roslyn#48176

@fjallemark
Copy link

fjallemark commented Nov 30, 2020

Is this same issue? I get CA1801 on parameter AssignedRoute i.e. when "subclassing" record and add properties on the sub-record.

public abstract record MovableEvent(long Id, DateTimeOffset Timestamp);
public abstract record InputEvent(long Id, DateTimeOffset Timestamp) : MovableEvent(Id, Timestamp);
public sealed record AssignRouteEvent(long Id, DateTimeOffset Timestamp, Route AssignedRoute) : InputEvent(Id, Timestamp);

@Evangelink
Copy link
Member

@fjallemark For me the issues look the same.

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 help wanted The issue is up-for-grabs, and can be claimed by commenting
Projects
None yet
4 participants