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 S1854 FP: Raises when variable is assigned in switch statement and not used in the first case #9472

Closed
mary-georgiou-sonarsource opened this issue Jun 26, 2024 · 0 comments
Assignees
Labels
Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Milestone

Comments

@mary-georgiou-sonarsource
Copy link
Contributor

mary-georgiou-sonarsource commented Jun 26, 2024

Repro steps

  void Repro()
  {
      char ch;
            switch (ch = GetAChar())   // Noncompliant FP
            {
                case 'A':
                    break;
                case 'B':
                    Console.WriteLine(ch);
                    break;
                default:
                    Console.WriteLine("Something");
                    break;
            }

      switch (ch = GetAChar())   // Does not raise
      {
          case 'A':
              Console.WriteLine(ch);
              break;
          default:
              Console.WriteLine("Something");
              break;
      }
      char GetAChar() => 'c';
  }
@mary-georgiou-sonarsource mary-georgiou-sonarsource changed the title Fix S1854 FP: Raises when variable is assigned in switch statement Fix S1854 FP: Raises when variable is assigned in switch statement and not use in the first case Jun 26, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource added Area: CFG/SE CFG and SE related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules. Sprint: LVA and removed Area: CFG/SE CFG and SE related issues. labels Jun 26, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource added this to the 9.30 milestone Jul 15, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource changed the title Fix S1854 FP: Raises when variable is assigned in switch statement and not use in the first case Fix S1854 FP: Raises when variable is assigned in switch statement and not used in the first case Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
None yet
Development

No branches or pull requests

1 participant