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 S1905: False Positive with 'default' #2295

Closed
nnpcYvIVl opened this issue Feb 19, 2019 · 1 comment
Closed

Update S1905: False Positive with 'default' #2295

nnpcYvIVl opened this issue Feb 19, 2019 · 1 comment
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@nnpcYvIVl
Copy link

nnpcYvIVl commented Feb 19, 2019

Description

This code throws S1905 but when I make the recommended change the code fails to compile with CS0411. Is this a false positive?

using System;

namespace S1905_False_Positive
{
    internal static class Class
    {
        public static void RunAction(Action action)
        {
            RunFunc(() => { action(); return default; }, (bool)default);
        }

        public static T RunFunc<T>(Func<T> func, T returnvalue = default)
        {
            try
            {
                return func();
            }
            catch (Exception)
            {
                return returnvalue;
            }
        }
    }
}

Related information

  • SonarC# Version: Latest
  • Visual Studio Version : 15.9.7
@Evangelink Evangelink changed the title S1905 False Positive Update S1905: False Positive with default Feb 22, 2019
@Evangelink Evangelink changed the title Update S1905: False Positive with default Update S1905: False Positive with 'default' Feb 22, 2019
@Evangelink
Copy link
Contributor

Hi @nnpcYvIVl,

This is indeed a FP! This is due to the unsupported (on our side) syntax default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

2 participants