Our website uses cookies to enhance your browsing experience.
Accept
to the top

Webinar: Let's make a programming language. Lexer - 29.04

>
>
>
V8008. Suspicious access to a...
menu mobile close menu
Additional information
toggle menu Contents

V8008. Suspicious access to a collection element by a constant index inside a loop.

Apr 03 2026

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