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 S1144 FP: Public indexer in nested class used in parent class #9652

Open
fiotti opened this issue Aug 20, 2024 · 1 comment
Open

Fix S1144 FP: Public indexer in nested class used in parent class #9652

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

Comments

@fiotti
Copy link

fiotti commented Aug 20, 2024

Description

Public indexer in a private inner class is erroneously always considered unused.

Repro steps

class Test
{
    class Inner
    {
        public int this[int test] => 0; // S1144: Remove the unused property 'this[]'.
    }

    public Test()
    {
        Inner inner = new();
        _ = inner[0]; // <-- used here
    }
}

Expected behavior

I didn't expect any diagnostics to be emitted.

Actual behavior

False positive.

Known workarounds

#pragma warning disable S1144

Related information

  • SonarLint for Visual Studio 2022, version 8.9.0.92083
  • Visual Studio Professional 2022 (64 bit), version 17.10.4
  • dotnet 8.0.303
  • MSBuild version 17.10.4+10fbfbf2e for .NET Framework, version 17.10.4.21802
  • Windows 11 Pro 23H2 22631.3880
@sebastien-marichal
Copy link
Contributor

Hello @fiotti,

I confirm this is a false positive!

Thank you for reporting it :)

@sebastien-marichal sebastien-marichal changed the title Fix S1144 FP: public indexer in nested class Fix S1144 FP: Public indexer in nested class used in parent class Aug 21, 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 21, 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