Skip to content

NET-2345 Fix S1116 FP: Empty statement is required after label at end of compound statement #9572

Description

@jilles-sg

Description

S1116 reports an issue when there is an empty statement after a label at the end of a compound statement. However, this empty statement (semicolon) is required by the syntax.

Repro steps

int[][] a = { new int[] { 1, 2 }, new int[] { 3, 4 } };
foreach (int[] aa in a) {
    foreach (int x in aa) {
        if (x < 2)
            goto next;
    }
next:;
}

Expected behavior

S1116 does not report an issue.

Actual behavior

S1116 complains about an empty statement on the line next:;

Apart from that, S907 correctly complains about the goto statement.

Known workarounds

Disable the rule or mark the issue as false positive.

Related information

  • C#/VB.NET Plugins version: csharp version 9.30.0.95878
  • Visual Studio version: 2022
  • MSBuild / dotnet version: .NET 6.0
  • SonarScanner for .NET version (if used): SonarScanner for MSBuild 5.14 (.NET Core) with SonarCloud
  • Operating System: Windows 10.0.17763.737

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    False PositiveRule IS triggered when it shouldn't be.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions