Lucky hour! Grab a free trial license — offer ends in 00:59:58. Claim now
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)) {
....
}
This diagnostic is classified as:
You can look at examples of errors detected by the V8001 diagnostic. |
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders: