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

>
>
>
V3011. Two opposite conditions were...
menu mobile close menu
Additional information
toggle menu Contents

V3011. Two opposite conditions were encountered. The second condition is always false.

14 Déc 2015

The analyzer has detected a potential logical error: two conditional statements executed in sequence contain mutually exclusive conditions.

Examples of such conditions:

  • "A == B" and "A != B";
  • "A > B" and "A <= B";
  • "A < B" and "B < A";
  • and so on.

This error can occur as a result of a typo or bad refactoring.

Consider the following example of incorrect code:

if (x == y)
  if (y != x)
    DoSomething(x, y);

In this fragment, the 'DoSomething' method will never be called because the second condition will always be false when the first one is true. One of the variables used in the comparison is probably wrong. In the second condition, for example, variable 'z' should have been used instead of 'x':

if (x == y)
  if (y != z)
    DoSomething(x, y);

This diagnostic is classified as:

You can look at examples of errors detected by the V3011 diagnostic.