Append Result Not Assigned Back to Slice

result of append is not used (govet)

Quick Answer

The append function returns a new slice but you are not assigning it back. Write s = append(s, item) to keep the result.

Why This Happens

Go's append function may need to allocate a new underlying array if the slice's capacity is exceeded. It returns the updated slice header, which may point to a new array. If you do not assign the result, the appended element is lost.

The Problem

func main() {
    s := []int{1, 2, 3}
    append(s, 4) // result not assigned
    fmt.Println(s) // still [1 2 3]
}

The Fix

func main() {
    s := []int{1, 2, 3}
    s = append(s, 4)
    fmt.Println(s) // [1 2 3 4]
}

Step-by-Step Fix

  1. 1

    Identify the unassigned append

    Find the append call whose result is not being assigned to any variable.

  2. 2

    Assign the result

    Write s = append(s, items...) to capture the potentially new slice.

  3. 3

    Verify the behavior

    Check that the slice reflects the new elements after the append.

Got the actual stack trace?

Paste it into our free AI explainer to get the cause and the fix for your specific case — no signup, nothing to install.

Explain my error

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free