Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V8001. Identical sub-expressions to...
menu mobile close menu
Additional information
toggle menu Contents

V8001. Identical sub-expressions to the left and to the right of the 'foo' operator.

Apr 03 2026

The analyzer has detected a code fragment that may contain a logic error. The code contains a binary expression in which the left and right subexpressions are identical. The operator of such an expression can be one of the following: <, >, <=, >=, ==, !=, &&, ||, -, /, &, | or ^.

The example:

func ConvertRGB(rgb RGBContainer) {
  if rgb.R > 1 && rgb.G > 1 && rgb.R > 1 {
    ....
  }
  ....
}

In this case, the condition contains two rgb.R > 1 subexpressions that are combined using the && operator. This error was caused by inattention, as there is no reason to use the same subexpression multiple times via the && logical operator.

The fixed code that will not trigger the analyzer is as follows:

func ConvertRGB(rgb RGBContainer) {
  if rgb.R > 1 && rgb.G > 1 && rgb.B > 1 {
    ....
  }
  ....
}

The analyzer compares blocks, considering the arrangement of the expression parts relative to the operators. The analyzer will also detect the error in the following code example:

if len([]rune(name)) > maxlength && 
   maxlength < len([]rune(name)) {
  ....
}