V8008. Suspicious access to a collection element by a constant index inside a loop.
The analyzer has detected a possible error related to accessing the same collection element on every iteration of a for loop using a constant index.
The example:
func ProcessParameters(method Method) {
var parameters []Parameter = method.GetParameters()
for i := 0; i < len(parameters); i++ {
typeName := parameters[0].TypeName
....
}
}
Developers intended to store some value of the i-th element from the parameters slice in the typeName variable at each iteration of the loop. However, they made a typo, so each iteration works with the same element—the first one.
The fixed code:
func ProcessParameters(method Method) {
var parameters []Parameter = method.GetParameters()
for i := 0; i < len(parameters); i++ {
typeName := parameters[i].TypeName
....
}
}