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 S4144 FP: when type constraints are used #7068

Closed
costin-zaharia-sonarsource opened this issue Apr 13, 2023 · 0 comments · Fixed by #9398
Closed

Fix S4144 FP: when type constraints are used #7068

costin-zaharia-sonarsource opened this issue Apr 13, 2023 · 0 comments · Fixed by #9398
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Milestone

Comments

@costin-zaharia-sonarsource
Copy link
Member

costin-zaharia-sonarsource commented Apr 13, 2023

Description

Given two methods with identical code and a single type parameter T; and, given different type constraints, a false S4144 (“Update this method so that its implementation is not identical to …”) message is generated.

Source: https://community.sonarsource.com/t/false-s4144-when-otherwise-identical-generic-methods-have-different-type-constraints/88443

Repro steps

public static class TypeConstraints
{
    public static int Use<T>(T? value) where T : struct => 1;

    public static int Use<T>(T? value) where T : class => 2;

    public static void First<T>(T? value) where T : struct // Secondary
    {
        var x = Use(value);
        Console.WriteLine(x);
    }

    public static void Second<T>(T? value) where T : class // Noncompliant
    {
        var x = Use(value);
        Console.WriteLine(x);
    }
}

Expected behavior

We should not raise any issues here. A different overload is used due to the type constraints.

Actual behavior

An issue is raised. See the code snippet.

Related information

  • C#/VB.NET Plugins version: 8.55
@costin-zaharia-sonarsource costin-zaharia-sonarsource added Type: False Positive Rule IS triggered when it shouldn't be. Area: C# C# rules related issues. labels Apr 13, 2023
@cristian-ambrosini-sonarsource cristian-ambrosini-sonarsource added this to the 9.7 milestone Jul 26, 2023
@cristian-ambrosini-sonarsource cristian-ambrosini-sonarsource changed the title S4144: FP when type constraints are used Fix S4144 FP: when type constraints are used Jul 26, 2023
@martin-strecker-sonarsource martin-strecker-sonarsource removed this from the 9.7 milestone Aug 4, 2023
@github-actions github-actions bot added this to Review in progress in Best Kanban Jun 4, 2024
@github-actions github-actions bot moved this from Review in progress to In progress in Best Kanban Jun 4, 2024
@Tim-Pohlmann Tim-Pohlmann moved this from In progress to Review in progress in Best Kanban Jun 5, 2024
@Tim-Pohlmann Tim-Pohlmann moved this from Review in progress to In progress in Best Kanban Jun 5, 2024
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Jun 5, 2024
@github-actions github-actions bot moved this from Review in progress to In progress in Best Kanban Jun 5, 2024
@martin-strecker-sonarsource martin-strecker-sonarsource added this to the 9.27 milestone Jun 10, 2024
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Jun 11, 2024
@martin-strecker-sonarsource martin-strecker-sonarsource removed this from the 9.27 milestone Jun 11, 2024
@github-actions github-actions bot moved this from Review in progress to In progress in Best Kanban Jun 11, 2024
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Jun 12, 2024
@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban Jun 12, 2024
@github-actions github-actions bot moved this from Review approved to Review in progress in Best Kanban Jun 13, 2024
@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban Jun 14, 2024
Best Kanban automation moved this from Review approved to Validate Peach Jun 20, 2024
@martin-strecker-sonarsource martin-strecker-sonarsource moved this from Validate Peach to Done in Best Kanban Jun 24, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource added this to the 9.28 milestone Jun 26, 2024
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
Best Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

5 participants