Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V8041. Modifying a field of a value...
menu mobile close menu
Analyzing projects
Additional information
toggle menu Contents

V8041. Modifying a field of a value receiver will have no effect. Consider using a pointer receiver.

Nov 10 2026

The analyzer has detected a method that modifies the receiver field passed by value. Such changes affect only a structure copy and do not affect the original object.

The example:

type Buffer struct {
  data []byte
}

func (b Buffer) Append(value byte) {
  b.data = append(b.data, value)
}

The Append method is declared with the Buffer receiver, which is passed by value. A copy of the object is created each time the method is called, so the b.data = append(b.data, value) expression modifies only the field of that copy. After the method execution is complete, the original object remains unchanged.

If a method is supposed to modify an object, use a pointer receiver:

func (b *Buffer) Append(value byte) {
  b.data = append(b.data, value)
}