{"record":{"id":"970b318729d44e1d","repo":"BoundaryML/baml","slug":"unsupported-statement-type-in-c-for-after-clause","errorCode":null,"errorMessage":"unsupported statement type in C-for after clause","messagePattern":"unsupported statement type in C-for after clause","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":1166,"sourceCode":"                                                        thir,\n                                                        run_llm_function,\n                                                        watch_handler,\n                                                        function_name,\n                                                    )\n                                                    .await?,\n                                                )?;\n                                                assign_to_expr(\n                                                    left,\n                                                    v,\n                                                    scopes,\n                                                    thir,\n                                                    run_llm_function,\n                                                    watch_handler,\n                                                    function_name,\n                                                )\n                                                .await?;\n                                            }\n                                            _ => bail!(\n                                                \"unsupported statement type in C-for after clause\"\n                                            ),\n                                        }\n                                    }\n                                    continue;\n                                }\n                                ControlFlow::Normal(_) => {\n                                    // Execute after statement if present\n                                    if let Some(after_stmt) = after {\n                                        // Execute the after statement in the current scope context\n                                        match after_stmt.as_ref() {\n                                            Statement::AssignOp {\n                                                left,\n                                                value,\n                                                assign_op,\n                                                ..\n                                            } => {\n                                                use crate::hir::AssignOp;","sourceCodeStart":1148,"sourceCodeEnd":1184,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L1148-L1184","documentation":"Raised by the BAML interpreter when executing the after clause of a C-style for loop. Only two statement kinds are permitted there: plain `Assign` and compound `AssignOp`. If the after clause contains any other statement type (a function call statement, declaration, nested loop, expression statement handled as another variant, etc.), the interpreter bails with this message.","triggerScenarios":"A BAML C-style for loop with a non-assignment statement in the third clause, e.g. `for (let i = 0; i < n; foo(i))`, a `let` declaration in the update position, or any statement the parser yields as something other than Assign/AssignOp.","commonSituations":"Porting C/JS update-clause expressions like `i++, arr.push(x)` or side-effecting calls into BAML's third for-clause; accidentally putting an initializer or body statement into the update slot.","solutions":["Move any non-assignment logic out of the after clause and put it at the end of the loop body instead.","Use a plain assignment in the after clause: `i = next(i)` style instead of a call statement.","Restructure as a foreach/while-style loop if the update step is complex.","Upgrade BAML to a version with broader after-clause support."],"exampleFix":"// before (BAML)\nfor (let i = 0; i < n; log(i)) { ... }\n// after\nfor (let i = 0; i < n; i += 1) { log(i); ... }","handlingStrategy":"validation","validationCode":"// Ensure the C-for update clause is a single assignment statement before running:\nconst isAssign = /^\\s*[A-Za-z_]\\w*(\\.[A-Za-z_]\\w*)*\\s*(=(?!=)|\\+=)\\s*[^;]+;?\\s*$/.test(afterClauseSrc);\nif (!isAssign) throw new Error(\"C-for after clause must be `var = expr` or `var += expr`\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never put function calls or declarations in the for-loop update clause.","Keep side effects (logging, pushes) at the end of the loop body.","Use foreach loops when the iteration step isn't a simple counter update.","Review ported C/JS loops clause-by-clause before committing."],"tags":["baml","interpreter","loops","unsupported-statement"],"backgroundTag":"unsupported-operation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}