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 S2094 FP: Implicit parameterless constructor widens the scope of the base class constructor #7591

Closed
rjgotten opened this issue Jul 13, 2023 · 1 comment · Fixed by #9081 or #9115
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Sprint: Hardening Fix FPs/FNs/improvements Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Milestone

Comments

@rjgotten
Copy link

rjgotten commented Jul 13, 2023

Description

S2094 regarding an empty class can be raised incorrectly in situations where an implicit parameterless constructor widens the scope modifier of the base class constructor. E.g. where an inherited class publishes a previously protected parameterless constructor.

Repro steps

public class Foo
{
  protected Foo() { }
}

public class Bar : Foo
{
}

Expected behavior

S2094 is not raised where the implicit parameterless constructor widens the scope modifier of the base class parameterless constructor.

Actual behavior

S2094 is raised.

Known workarounds

Explicitly implement the constructor. E.g.

public class Foo
{
  protected Foo() { }
}

public class Bar : Foo
{
  public Bar() : base() { }
}

However, this (correctly!) raises S3253 regarding having defined a redundant constructor.
In effect, the only way to fix this is to suppress S2094.

Related information

  • C#/VB.NET Plugins version : C# 9.4.0.72892 (SonarLint 7.0.0.74072)
  • Visual Studio version: 17.6.5
  • MSBuild / dotnet version: dotnet 7.0.306
  • Operating System: Windows 11
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added Type: False Positive Rule IS triggered when it shouldn't be. Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. labels Jul 17, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource changed the title Fix S2094 FP: Does not take into account effect of implicit parameterless constructor Fix S2094 FP: Implicit parameterless constructor widens the scope of the base class constructor Jul 17, 2023
@zsolt-kolbay-sonarsource
Copy link
Contributor

Hi @rjgotten. Thank you for reporting this. Confirmed as False Positive.

@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource removed their assignment Jul 17, 2023
@Tim-Pohlmann Tim-Pohlmann added the Sprint: Hardening Fix FPs/FNs/improvements label Apr 10, 2024
@Tim-Pohlmann Tim-Pohlmann added this to the 9.24 milestone Apr 10, 2024
@Tim-Pohlmann Tim-Pohlmann added this to To do in Best Kanban Apr 10, 2024
@Tim-Pohlmann Tim-Pohlmann self-assigned this Apr 11, 2024
@Tim-Pohlmann Tim-Pohlmann moved this from To do to In progress in Best Kanban Apr 11, 2024
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Apr 11, 2024
@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban Apr 12, 2024
@github-actions github-actions bot moved this from Review approved to Review in progress in Best Kanban Apr 12, 2024
@Tim-Pohlmann Tim-Pohlmann moved this from Review in progress to In progress in Best Kanban Apr 12, 2024
@Tim-Pohlmann Tim-Pohlmann moved this from In progress to Review approved in Best Kanban Apr 12, 2024
Best Kanban automation moved this from Review approved to Validate Peach Apr 12, 2024
@Tim-Pohlmann Tim-Pohlmann moved this from Validate Peach to In progress in Best Kanban Apr 16, 2024
@Tim-Pohlmann Tim-Pohlmann removed their assignment Apr 17, 2024
@Tim-Pohlmann Tim-Pohlmann moved this from In progress to Review in progress in Best Kanban Apr 17, 2024
@CristianAmbrosini CristianAmbrosini moved this from Review in progress to In progress in Best Kanban Apr 17, 2024
@Tim-Pohlmann Tim-Pohlmann moved this from In progress to Review in progress in Best Kanban Apr 17, 2024
@CristianAmbrosini CristianAmbrosini moved this from Review in progress to Review approved in Best Kanban Apr 18, 2024
@Tim-Pohlmann Tim-Pohlmann moved this from Review approved to Validate Peach in Best Kanban Apr 18, 2024
@CristianAmbrosini CristianAmbrosini moved this from Validate Peach to Done in Best Kanban Apr 19, 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. Area: VB.NET VB.NET rules related issues. Sprint: Hardening Fix FPs/FNs/improvements Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Best Kanban
  
Done
5 participants