{"record":{"id":"d792a5f9e649cf5a","repo":"BoundaryML/baml","slug":"push-can-only-be-called-on-a-variable-at","errorCode":null,"errorMessage":"push() can only be called on a variable at {:?}","messagePattern":"push\\(\\) can only be called on a variable at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2249,"sourceCode":"                    _ => bail!(\"method name must be an identifier at {:?}\", meta.0),\n                };\n\n                // For mutating methods like push(), we need the cell reference\n                if method_name == \"push\" {\n                    // Get the receiver as a reference (cell) if possible\n                    let receiver_eval = evaluate_expr(\n                        receiver,\n                        scopes,\n                        thir,\n                        run_llm_function,\n                        watch_handler,\n                        function_name,\n                    )\n                    .await?;\n\n                    let receiver_cell = match receiver_eval {\n                        EvalValue::Reference(cell) => cell,\n                        _ => bail!(\"push() can only be called on a variable at {:?}\", meta.0),\n                    };\n\n                    // Evaluate arguments\n                    let mut arg_vals: Vec<BamlValueWithMeta<ExprMetadata>> =\n                        Vec::with_capacity(args.len());\n                    for arg in args.iter() {\n                        arg_vals.push(expect_value(\n                            evaluate_expr(\n                                arg,\n                                scopes,\n                                thir,\n                                run_llm_function,\n                                watch_handler,\n                                function_name,\n                            )\n                            .await?,\n                        )?);\n                    }","sourceCodeStart":2231,"sourceCodeEnd":2267,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2231-L2267","documentation":"The mutating array method `push()` must be invoked on a variable (an lvalue the interpreter holds as a mutable reference cell). If evaluating the receiver does not yield an `EvalValue::Reference` — e.g. it is a temporary value or a literal — the interpreter cannot mutate it and throws.","triggerScenarios":"Calling `push` on anything that is not a variable: a literal array `[1,2].push(3)`, the result of another expression/function call `getList().push(x)`, or a field access not backed by a cell.","commonSituations":"Trying to append to a function's return value inline; appending to an array literal; pushing onto a value returned from a map/filter pipeline instead of a stored variable.","solutions":["Assign the array to a variable first, then call push on that variable","If the array comes from a function, store the result: `let xs = getItems(); xs.push(x);`","For immutable use, rebuild the list with concatenation instead of push"],"exampleFix":"// before\n[1, 2].push(3)\n// after\nlet arr = [1, 2];\narr.push(3);","handlingStrategy":"validation","validationCode":"// receiver must be a variable before push\nif (!isVariableNode(receiverExpr)) { throw new Error('assign to a variable before calling push'); }","typeGuard":null,"tryCatchPattern":"try { arr.push(x); } catch (e) { if (String(e).includes('push() can only be called on a variable')) { /* bind to variable and retry */ } else { throw e; } }","preventionTips":["Store arrays in named variables before mutating","Never call push on literals or function results","Keep mutation on declared variables only"],"tags":["runtime","arrays","mutation","interpreter"],"backgroundTag":"unsupported-operation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}