{"record":{"id":"ac087749093c6bc1","repo":"BoundaryML/baml","slug":"method-name-must-be-an-identifier-at","errorCode":null,"errorMessage":"method name must be an identifier at {:?}","messagePattern":"method name must be an identifier at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2231,"sourceCode":"                        watch_handler,\n                        function_name,\n                    )\n                    .await?,\n                )?;\n\n                let result = evaluate_unary_op(operator, &val, meta)?;\n                EvalValue::Value(result)\n            }\n            Expr::MethodCall {\n                receiver,\n                method,\n                args,\n                meta,\n            } => {\n                // Extract method name\n                let method_name = match method.as_ref() {\n                    Expr::Var(name, _) => name.clone(),\n                    _ => 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),","sourceCodeStart":2213,"sourceCodeEnd":2249,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2213-L2249","documentation":"Method-call expressions (`receiver.method(args)`) in the BAML interpreter require the method portion to be a plain identifier. If the parser produced anything else in the method position (e.g. a nested expression, an indexed access, a call result), evaluation bails with this error.","triggerScenarios":"Calling a method via a non-identifier expression, such as `obj[\"push\"](x)`, `(getFn())(arg)`, or chained access where the method name is computed dynamically.","commonSituations":"Dynamic method dispatch attempted in BAML code (methods chosen from a variable or map lookup); mis-parenthesized chained calls; code generated by a template that interpolated a method expression.","solutions":["Use a literal method name identifier at the call site: `obj.push(item)`","Bind the result to a variable and call a known method on it instead of dynamic dispatch","Check parentheses/bracket placement so the compiler parses the method as a Var expression"],"exampleFix":"// before\narr[\"push\"](item)\n// after\narr.push(item)","handlingStrategy":"validation","validationCode":"// ensure the call shape is receiver.literalMethod(args)\nif (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(methodName)) { throw new Error('method name must be an identifier'); }","typeGuard":"function isMethodIdentifier(e) { return e != null && e.kind === 'Var' && typeof e.name === 'string'; }","tryCatchPattern":"try { evalCall(); } catch (e) { if (String(e).includes('method name must be an identifier')) { /* rewrite call with literal method name */ } else { throw e; } }","preventionTips":["Always write method calls with literal identifiers","Avoid dynamic method dispatch in BAML code","Check parentheses when chaining calls"],"tags":["runtime","method-call","interpreter","syntax"],"backgroundTag":"invalid-argument-format","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"}