Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top

Webinar: Let's make a programming language. Part 1. Intro - 20.02

>
>
>
V3174. Suspicious subexpression in a...
menu mobile close menu
Additional information
toggle menu Contents

V3174. Suspicious subexpression in a sequence of similar comparisons.

24 Jan 2022

The analyzer has detected a code fragment that most likely contains a typo. The chain of same-type comparisons of class members has an expression different from others. This expression compares members with different names, while the rest of the expressions compare members with the same names.

Look at the example:

public void Foo(TestClass a, TestClass b)
{
  if (a.x == b.x && a.y == b.y && a.z == b.y)
  {
    ....
  }
}

In this fragment, expression 'a.z == b.y' is different from the rest expressions in the chain. Most likely, it's a typo that appeared when the developer edited a copied text. The correct code which won't look suspicious for the analyzer:

public void Foo(TestClass a, TestClass b)
{
  if (a.x == b.x && a.y == b.y && a.z == b.z)
  {
    ....
  }
}

The analyzer issues a warning when the length of the comparison chain is more than two expressions.

This diagnostic is classified as: