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 warning shown on build/analysis, disappears when source file is opened #1713

Closed
markashleybell opened this issue Jun 6, 2018 · 6 comments
Labels
Bug The product is not behaving according to its current intended design Resolution-Duplicate

Comments

@markashleybell
Copy link

Analyzer package

Microsoft.CodeAnalysis.FxCopAnalyzers, version 2.6.1

Analyzer

ReviewUnusedParameters

Repro steps

I have several custom error types in my project, all derived from a base type:

public class Error
{
    public Error(string description)
        : this(description, null) { }

    public Error(Exception exception)
        : this(exception?.Message, exception) { }

    public Error(string description, Exception exception)
    {
        Description = description;
        Exception = exception;
    }

    public virtual string Description { get; }

    public virtual Exception Exception { get; }
}

public class PathNotFoundError : Error
{
    public PathNotFoundError(string path, Exception exception)
        : base(exception) => Description = $"{path} was not found";

    public override string Description { get; }
}

When I run code analysis in VS2017 (ALT+F11) or build the solution, I get a bunch of CA1801 warnings in the Error List referring to the subclassed error types. For the example above the error is:

Warning CA1801 Parameter path of method .ctor is never used. Remove the parameter or use it in the method body.

However, that parameter is used, and indeed when I double-click the warning in the error list, as soon as the source file opens in VS the warning disappears.

Expected behavior

CA1801 warning should not appear in this case.

Actual behavior

CA1801 warnings are added to error list when Code Analysis is run or on solution build, but disappear on opening the source file.

@mavasani
Copy link
Contributor

mavasani commented Jun 6, 2018

Dupe of #1713 #1606 and #1559.

FYI @jinujoseph @heejaechang, error list behavior is due to compilation end action bug.

@sharwell
Copy link
Member

sharwell commented Jun 6, 2018

Parameter path of method .ctor is never used.

@mavasani do we have a bug that this should have included quotes, like this?

Parameter 'path' of method '.ctor' is never used.

@mavasani mavasani added Bug The product is not behaving according to its current intended design Resolution-Duplicate labels Jun 6, 2018
@mavasani mavasani closed this as completed Jun 6, 2018
@mavasani
Copy link
Contributor

mavasani commented Jun 6, 2018

@sharwell I do not believe so. I think quite a few of our diagnostic messages were created by an automated tool that ported messages from old FxCop implementation. I will file an issue to audit the messages.

@markashleybell
Copy link
Author

Thanks for taking a look; however, I don't think this is a duplicate.

After enabling full solution analysis (which I think seems to be the suggested fix from reading through some other referenced issues), the inconsistency with the disappearing messages is gone. So that part, I would agree, is covered by the other issue.

But the real issue is that I shouldn't see the CA1801 warning at all in this case, as the parameter is used in the constructor. Should I create a separate issue for that, or edit this one?

@mavasani
Copy link
Contributor

mavasani commented Jun 6, 2018

@markashleybell Sorry, my bad that I put a wrong dupe ID in #1713 (comment). The other issue is dupe of #1606, which was recently fixed in Roslyn and should not repro in VS15.8

@markashleybell
Copy link
Author

@mavasani That's great, looks like that will solve my issue then! Thanks for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The product is not behaving according to its current intended design Resolution-Duplicate
Projects
None yet
Development

No branches or pull requests

3 participants