BoundaryML/baml · error
unsupported assign op in C-for after clause
Error message
unsupported assign op in C-for after clause
What it means
This error is raised by the BAML expression interpreter (handle_statement in interpret.rs) while executing the after-clause of a C-style for loop (`for (init; cond; after)`). When a loop body executes `continue` or finishes normally, the interpreter runs the after statement, but it only supports plain assignment (`i = ...`) and `+=` (AddAssign). Any other compound assign operator (`-=`, `*=`, `/=`, etc.) in the after clause hits this bail!.
Source
Thrown at engine/baml-compiler/src/thir/interpret.rs:1128
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?;
}
Statement::Assign { left, value } => {
let v = expect_value(
evaluate_expr(
value,View on GitHub (pinned to bd85ce9dee)
Solutions
- Rewrite the after clause to use `+=` only, e.g. `i -= 1` becomes `i += -1`.
- Rewrite the after clause as a plain assignment: `i = i * 2` instead of `i *= 2`.
- Replace the C-style for loop with a foreach loop over a range if the loop is a simple counter.
- Upgrade BAML: newer versions may support more assign operators in the after clause.
Example fix
// before (BAML)
for (let i = 10; i > 0; i -= 1) { ... }
// after
for (let i = 10; i > 0; i += -1) { ... } Defensive patterns
Strategy: validation
Validate before calling
// Before running a BAML C-style for loop, ensure the after clause only uses += or plain assignment:
const ALLOWED = /^^\s*[A-Za-z_]\w*\s*(\+=|=)\s*.+$/;
if (!ALLOWED.test(afterClauseSrc)) {
throw new Error("C-for after clause must use '=' or '+=' (e.g. 'i += 1' or 'i = i * 2')");
} Prevention
- Restrict C-for update clauses to `i += step` or `i = expr` in your BAML style guide.
- Write decrement loops as `i += -1`.
- Prefer foreach-over-range loops, which avoid the after clause entirely.
- Add a lint/test that greps BAML sources for `-=`/`*=`/`/=` in for-update position.
When it happens
Trigger: A BAML C-style for loop whose after clause uses a compound assign operator other than `+=`, e.g. `for (let i = 0; i < 10; i -= 1)` or `i *= 2`. The error fires when the loop body completes an iteration or a `continue` executes, not at parse time.
Common situations: Porting loop idioms from C/JS/Python into BAML (`i--`, `i *= 2`, `i /= 2` in the update clause) before the interpreter added support for those operators; writing decrementing loops.
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
- unsupported statement type in C-for after clause
- unsupported types for %= operator
- bitwise ^= requires integer operands
- bitwise &= requires integer operands
- bitwise |= requires integer operands
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/a04ded2fe9026f9b.
Report an issue: GitHub.