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

Fix S3655 FP: HasValue checked with Pattern matching #6682

Closed
pavel-mikula-sonarsource opened this issue Jan 27, 2023 · 4 comments · Fixed by #6914
Closed

Fix S3655 FP: HasValue checked with Pattern matching #6682

pavel-mikula-sonarsource opened this issue Jan 27, 2023 · 4 comments · Fixed by #6914
Assignees
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Sprint: SE Short-lived* label for epic MMF-3077 *troll Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
Milestone

Comments

@pavel-mikula-sonarsource
Copy link
Contributor

pavel-mikula-sonarsource commented Jan 27, 2023

Reported here: https://community.sonarsource.com/t/rule-c-s3655-false-positive-for-pattern/81703

public struct Repro_6682
{
    public bool SomeProperty { get; }

    public void PatternMatching(Repro_6682? arg, bool condition)
    {
        if (condition)
        {
            arg = null;
        }

        if (arg is { SomeProperty: true })   // A null check
        {
            var value = arg.Value;  // Noncompliant FP
        }

        if (arg is { })   // A null check
        {
            var value = arg.Value;  // Noncompliant FP
        }
    }
}
@pavel-mikula-sonarsource pavel-mikula-sonarsource added Area: CFG/SE CFG and SE related issues. Area: C# C# rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules. labels Jan 27, 2023
@Gakk
Copy link

Gakk commented Jan 27, 2023

Thanks for confirming this issue @pavel-mikula-sonarsource 👍

You gave a timeframe for Q1 on the community:

We plan to rework this rule in Q1 and that should also fix this issue.

Currently our developers get failed on the quality gate:
image

Is there any way to modify this rule using SonarCloud, without lowering the quality gate for all rules?

@pavel-mikula-sonarsource
Copy link
Contributor Author

You should mark it as False Positive in SonarCloud UI

@Gakk
Copy link

Gakk commented Jan 27, 2023

You should mark it as False Positive in SonarCloud UI

I thought marking in SonarCloud UI also involved manually overriding check on GitHub pull request (or re-run analyze), but your integration updated both comment and check immediately! Kudos! 🥳🚀

@pavel-mikula-sonarsource pavel-mikula-sonarsource added the Sprint: SE Short-lived* label for epic MMF-3077 *troll label Feb 27, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to the 8.56 milestone Feb 27, 2023
@github-actions github-actions bot added this to To do in Best Kanban Feb 27, 2023
@antonioaversa antonioaversa moved this from To do to In progress in Best Kanban Mar 16, 2023
@antonioaversa antonioaversa linked a pull request Mar 16, 2023 that will close this issue
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Mar 16, 2023
@github-actions github-actions bot moved this from Review in progress to In progress in Best Kanban Mar 17, 2023
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Mar 20, 2023
@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban Mar 21, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource moved this from Review approved to Done in Best Kanban Mar 22, 2023
@martin-strecker-sonarsource
Copy link
Contributor

Fixed as part of sprint 8.56

Best Kanban automation moved this from Done to Validate Peach Apr 18, 2023
@martin-strecker-sonarsource martin-strecker-sonarsource moved this from Validate Peach to Done in Best Kanban Apr 18, 2023
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. Area: CFG/SE CFG and SE related issues. Sprint: SE Short-lived* label for epic MMF-3077 *troll Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
Best Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

4 participants