{"record":{"id":"a7801febaa248523","repo":"BoundaryML/baml","slug":"expressions-that-evaluate-to-functions-are-not-supported-yet","errorCode":null,"errorMessage":"expressions that evaluate to functions are not supported yet","messagePattern":"expressions that evaluate to functions are not supported yet","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/codegen.rs","lineNumber":1248,"sourceCode":"                    self.compile_expression(value);\n                }\n\n                for (key, _) in pairs {\n                    self.emit_string_literal(key);\n                }\n\n                self.emit(Instruction::AllocMap(pairs.len()));\n            }\n\n            thir::Expr::Call {\n                func,\n                args,\n                type_args,\n                ..\n            } => {\n                let name = match func.as_ref() {\n                    thir::Expr::Var(name, _) => name,\n                    _ => panic!(\"expressions that evaluate to functions are not supported yet\"),\n                };\n\n                // Push the function onto the stack\n                if let Some(&index) = self.globals.get(name) {\n                    self.emit(Instruction::LoadGlobal(index));\n                } else {\n                    panic!(\"undefined function: {name}\");\n                }\n\n                // Push the arguments onto the stack\n                for arg in args {\n                    self.compile_expression(arg);\n                }\n\n                // Type parameter. TODO: Generic way of handling this?\n                if name == \"baml.fetch_as\" {\n                    let type_index = self.objects.insert(Object::BamlType(type_args[0].clone()));\n                    let const_index = self.add_constant(Value::Object(type_index));","sourceCodeStart":1230,"sourceCodeEnd":1266,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/codegen.rs#L1230-L1266","documentation":"BAML function-call compilation only supports calling a function by name (an identifier expression). If the callee expression is anything else — an arbitrary expression that evaluates to a function value — the code generator panics because first-class function values are not yet supported in this compiler path. Note the interpreter (THIR interpret) does support function values, so this is a codegen-only limitation.","triggerScenarios":"Compiling a Call expression whose func field is not Expr::Var, e.g. calling the result of an expression like (get_fn())(...), calling a function stored in a variable, or invoking a method expression directly rather than via method-call syntax.","commonSituations":"Porting interpreter-friendly BAML (assigning functions to intermediate expressions) to compiled bytecode; attempting higher-order function calls in generated code; refactors that replaced a direct function name with an expression.","solutions":["Call the function directly by its identifier name instead of via an intermediate expression","Bind the result differently: call the function where its name is in scope rather than passing/deriving the callee dynamically","If you need dynamic dispatch, use explicit branching (if/else calling named functions)","Track BAML compiler releases for first-class function support; this is an explicit 'not supported yet' limitation"],"exampleFix":"// before\nlet f = my_function\nf(args)\n// after\nmy_function(args)","handlingStrategy":"validation","validationCode":"fn validate_call_target(expr: &Expr) -> Result<(), String> {\n    match expr { Expr::Var(_) => Ok(()), _ => Err(\"callee must be a named function identifier\".into()) }\n}","typeGuard":"fn is_named_callee(expr: &Expr) -> bool { matches!(expr, Expr::Var(_, _)) }","tryCatchPattern":null,"preventionTips":["Never assign functions to variables or expressions in compiled BAML code","Always invoke functions directly by identifier","Avoid higher-order function patterns until first-class functions are supported","Review BAML release notes for function-value support before using dynamic callee patterns"],"tags":["compiler","codegen","panic","unsupported-feature","functions"],"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"}