{"record":{"id":"bbba85b8d832a972","repo":"BoundaryML/baml","slug":"unsupported-types-for-in-c-for-after-clause","errorCode":null,"errorMessage":"unsupported types for += in C-for after clause","messagePattern":"unsupported types for \\+= in C-for after clause","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":1123,"sourceCode":"                                                    evaluate_expr(\n                                                        value,\n                                                        scopes,\n                                                        thir,\n                                                        run_llm_function,\n                                                        watch_handler,\n                                                        function_name,\n                                                    )\n                                                    .await?,\n                                                )?;\n\n                                                let result_val = match assign_op {\n                                                    AssignOp::AddAssign => {\n                                                        match (current_val.clone(), rhs_val.clone()) {\n                                                    (\n                                                        BamlValueWithMeta::Int(a, meta),\n                                                        BamlValueWithMeta::Int(b, _),\n                                                    ) => BamlValueWithMeta::Int(a + b, meta),\n                                                    _ => bail!(\n                                                        \"unsupported types for += in C-for after clause\"\n                                                    ),\n                                                }\n                                                    }\n                                                    _ => bail!(\n                                                    \"unsupported assign op in C-for after clause\"\n                                                ),\n                                                };\n                                                assign_to_expr(\n                                                    left,\n                                                    result_val,\n                                                    scopes,\n                                                    thir,\n                                                    run_llm_function,\n                                                    watch_handler,\n                                                    function_name,\n                                                )\n                                                .await?;","sourceCodeStart":1105,"sourceCodeEnd":1141,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L1105-L1141","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Initialize the loop counter as Int (`let i = 0`, not `0.0`).","Ensure the step expression is Int (convert/round float steps before the loop).","Check the loop body doesn't reassign the counter to a non-Int value."],"exampleFix":"// before (BAML)\nfor (let i = 0.0; i < n; i += 0.5) { ... } // error: unsupported types for += in C-for after clause\n\n// after\nfor (let i = 0; i < n * 2; i += 1) { let x = toFloat(i) / 2.0; ... }","handlingStrategy":"type-guard","validationCode":"// validate the counter and step are ints before running the loop\nfunction assertForStep(counterInit: unknown, step: unknown): void {\n  if (!Number.isInteger(counterInit) || !Number.isInteger(step)) {\n    throw new Error(\"C-for counter and += step must be Int in BAML\");\n  }\n}","typeGuard":"const isInt = (v: unknown): v is number => typeof v === \"number\" && Number.isInteger(v);","tryCatchPattern":"try {\n  await runBaml(program);\n} catch (e) {\n  if (String(e).includes(\"unsupported types for += in C-for after clause\")) {\n    // re-initialize the counter as Int and use an integer step, then retry\n  } else { throw e; }\n}","preventionTips":["Initialize loop counters with integer literals (0, not 0.0).","Convert fractional steps into integer steps by scaling the loop bound instead.","Validate step values derived from config/LLM output are integers.","Don't reassign the counter to non-Int values inside the loop body."],"tags":["baml","interpreter","loop","arithmetic","type-mismatch"],"backgroundTag":"unsupported-operation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}