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
....
}
}
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: