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: Implicit object creation expression #9654

Open
nrankin18 opened this issue Aug 21, 2024 · 1 comment
Open

Fix S4144 FP: Implicit object creation expression #9654

nrankin18 opened this issue Aug 21, 2024 · 1 comment
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.

Comments

@nrankin18
Copy link

Description

Rule S4144 is raised when two methods have identical bodies but are not identical due to different return types.

Repro steps

public record Foo(string A);
public record Bar(string A);

private static Foo Test1()
{
  string s = "A";
  return new(s);
}

private static Bar Test2() // S4144 is flagged here
{
  string s = "A";
  return new(s);
}

Expected behavior

S4144 should not be raised since the methods are different (one returns Foo, the other Bar).

Actual behavior

S4144 is raised.

Known workarounds

Inhibit S4144

Related information

  • C#/VB.NET Plugins version: 8.2.1.96841
  • Visual Studio version: 17.11.1
  • dotnet version: 8.0
  • SonarScanner for .NET version (if used): n/a
  • Operating System: Windows 11
@sebastien-marichal
Copy link
Contributor

Hello @nrankin18,

Thank you for reporting this issue; I confirm this to be a false positive.

The issue is due to the usage of implicit object creation new().
When using explicit object creation, the issue does not raise.

I will add it to our backlog to fix it.

Have a nice day!

@sebastien-marichal sebastien-marichal changed the title Fix S4144 FP: Non-identical method false positive Fix S4144 FP: Implicit object creation expression Aug 23, 2024
@sebastien-marichal sebastien-marichal added Type: False Positive Rule IS triggered when it shouldn't be. Area: C# C# rules related issues. labels Aug 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
None yet
Development

No branches or pull requests

3 participants