Another false positive for S2583 - Conditionally executed code should be reachable

Hi,

The following code gives a warning for the second part of the if-statement but is does print 0

  • S2583 - Conditionally executed code should be reachable
    [Test]
    public void TestRuleS2583_part2()
    {
      var ids = new int[1000];
      for (var i = 0; i < ids.Length; i++)
      {
        if (i % 100 != 0 || i <= 0)
        {
          System.Diagnostics.Debug.WriteLine(i);
        }
      }
    }

Environment:

  • Visual Studio 17.8.0
  • SonarLint 7.4.0

Kind regards,

Valentijn

Hi @Valentijn thanks for this report as well. The analyzer doesn’t know about the length of arrays yet. If you replace ids.Length it works as expected. We might be able to add this functionality in the future.
I added an issue to our backlog: