golang/go · error

clause %q: expected colon

Error message

clause %q: expected colon

What it means

Returned by parseScoreAdj for a single score-adjustment clause that has no colon, i.e. strings.Split(clause, ":") produced fewer than 2 elements. Each clause must look like <adjustmentName>:<integer>, so a missing colon means the clause is malformed.

Source

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

func adjStringToVal(s string) (scoreAdjustTyp, bool) {
	for adj := scoreAdjustTyp(1); adj < sentinelScoreAdj; adj <<= 1 {
		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
}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Rewrite the clause as name:value, e.g. panicPathAdj:40.
  2. Separate multiple clauses with / and ensure each has exactly one colon.
  3. Cross-check names against the scoreAdjustTyp String() outputs.

Example fix

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

Strategy: validation

Validate before calling

// Pre-validate each clause has exactly one colon.
for _, c := range strings.Split(val, "/") {
    if !strings.Contains(c, ":") {
        return fmt.Errorf("clause %q missing ':'", c)
    }
}

Prevention

When it happens

Trigger: An inlheur adjustment clause like "panicPathAdj" (no ":value") is parsed; len(elems) < 2 fires the error naming the offending clause.

Common situations: Compiler development: typo in the -d=inlheuradjustments flag value, missing the value half, or copy-paste dropping the colon.

Related errors


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