golang/go · error

clause %q has %d elements, wanted 2

Error message

clause %q has %d elements, wanted 2

What it means

Returned by parseScoreAdj when a clause splits into something other than exactly two colon-separated elements. Because the colon character itself can appear if the value contains a colon, this fires when there are 3+ elements, i.e. the clause has extra colons (e.g. name:value:extra).

Source

Thrown at src/cmd/compile/internal/inline/inlheur/scoring.go:129

		if adj.String() == s {
			return adj, true
		}
	}
	return 0, false
}

func parseScoreAdj(val string) error {
	clauses := strings.Split(val, "/")
	if len(clauses) == 0 {
		return fmt.Errorf("no clauses")
	}
	for _, clause := range clauses {
		elems := strings.Split(clause, ":")
		if len(elems) < 2 {
			return fmt.Errorf("clause %q: expected colon", clause)
		}
		if len(elems) != 2 {
			return fmt.Errorf("clause %q has %d elements, wanted 2", clause,
				len(elems))
		}
		adj, ok := adjStringToVal(elems[0])
		if !ok {
			return fmt.Errorf("clause %q: unknown adjustment", clause)
		}
		val, err := strconv.Atoi(elems[1])
		if err != nil {
			return fmt.Errorf("clause %q: malformed value: %v", clause, err)
		}
		adjValues[adj] = val
	}
	return nil
}

func adjValue(x scoreAdjustTyp) int {
	if val, ok := adjValues[x]; ok {
		return val

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Ensure exactly one colon per clause with a single integer after it.
  2. Remove stray characters or extra segments after the value.
  3. Validate by mentally splitting on ":" — the result must be a 2-element slice.

Example fix

// before
-d=inlheuradjustments=panicPathAdj:40:99
// after
-d=inlheuradjustments=panicPathAdj:40
Defensive patterns

Strategy: validation

Validate before calling

// Ensure exactly two elements per clause.
for _, c := range strings.Split(val, "/") {
    if len(strings.Split(c, ":")) != 2 {
        return fmt.Errorf("clause %q must be name:value", c)
    }
}

Prevention

When it happens

Trigger: A clause like panicPathAdj:40:99 splits into 3 elements; len(elems) != 2 triggers the error reporting the actual element count.

Common situations: Compiler development: accidentally including a second colon, an extra value, or a trailing colon like panicPathAdj:40:.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/ac2b454d40e860cb. Report an issue: GitHub.