BoundaryML/baml · error

unsupported types for += in C-for after clause

Error message

unsupported types for += in C-for after clause

What it means

Raised by the BAML interpreter while executing the after/step clause of a C-style for loop when it evaluates `+=`: the operation is only supported for Int/Int operands, and any other type pair bails with this message. It is the loop-scoped variant of the general `unsupported types for += operator` error.

Source

Thrown at engine/baml-compiler/src/thir/interpret.rs:1123

                                                    evaluate_expr(
                                                        value,
                                                        scopes,
                                                        thir,
                                                        run_llm_function,
                                                        watch_handler,
                                                        function_name,
                                                    )
                                                    .await?,
                                                )?;

                                                let result_val = match assign_op {
                                                    AssignOp::AddAssign => {
                                                        match (current_val.clone(), rhs_val.clone()) {
                                                    (
                                                        BamlValueWithMeta::Int(a, meta),
                                                        BamlValueWithMeta::Int(b, _),
                                                    ) => BamlValueWithMeta::Int(a + b, meta),
                                                    _ => bail!(
                                                        "unsupported types for += in C-for after clause"
                                                    ),
                                                }
                                                    }
                                                    _ => bail!(
                                                    "unsupported assign op in C-for after clause"
                                                ),
                                                };
                                                assign_to_expr(
                                                    left,
                                                    result_val,
                                                    scopes,
                                                    thir,
                                                    run_llm_function,
                                                    watch_handler,
                                                    function_name,
                                                )
                                                .await?;

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Initialize the loop counter as Int (`let i = 0`, not `0.0`).
  2. Ensure the step expression is Int (convert/round float steps before the loop).
  3. Check the loop body doesn't reassign the counter to a non-Int value.

Example fix

// before (BAML)
for (let i = 0.0; i < n; i += 0.5) { ... } // error: unsupported types for += in C-for after clause

// after
for (let i = 0; i < n * 2; i += 1) { let x = toFloat(i) / 2.0; ... }
Defensive patterns

Strategy: type-guard

Validate before calling

// validate the counter and step are ints before running the loop
function assertForStep(counterInit: unknown, step: unknown): void {
  if (!Number.isInteger(counterInit) || !Number.isInteger(step)) {
    throw new Error("C-for counter and += step must be Int in BAML");
  }
}

Type guard

const isInt = (v: unknown): v is number => typeof v === "number" && Number.isInteger(v);

Try / catch

try {
  await runBaml(program);
} catch (e) {
  if (String(e).includes("unsupported types for += in C-for after clause")) {
    // re-initialize the counter as Int and use an integer step, then retry
  } else { throw e; }
}

Prevention

When it happens

Trigger: A `for (init; cond; i += step)` loop where `i` or `step` is not an Int at runtime — e.g. the initializer set `i` to a Float, or `step` is a float/string from config or LLM output.

Common situations: Loop counters initialized to `0.0` or incremented by computed float steps; step values parsed from prompt output; counters that were reassigned to strings inside the body.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/bbba85b8d832a972. Report an issue: GitHub.