Mixture of Field:Value and Value Initializers

mixture of field:value and value initializers

Quick Answer

You are mixing named and positional field initialization in a struct literal. Use either all named fields or all positional values, not both.

Why This Happens

Go struct literals can use either field:value syntax or positional syntax, but not a mixture. Positional syntax requires providing all fields in order and is fragile. Named syntax is recommended because it is explicit and survives field reordering.

The Problem

type Point struct {
    X int
    Y int
    Z int
}

p := Point{X: 1, 2, Z: 3} // mixture of field:value and value

The Fix

p := Point{X: 1, Y: 2, Z: 3}

Step-by-Step Fix

  1. 1

    Identify the mixed initializer

    Find the struct literal that mixes named and positional field values.

  2. 2

    Choose one style

    Pick either all named fields (recommended) or all positional values.

  3. 3

    Update the literal

    Add field names to all values or remove all field names.

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