{"record":{"id":"5269e6bfb5fa8da4","repo":"BoundaryML/baml","slug":"invalid-left-hand-of-assignment-only-variables-instance","errorCode":null,"errorMessage":"Invalid left hand of assignment, only variables, instance fields and array elements can be assigned","messagePattern":"Invalid left hand of assignment, only variables, instance fields and array elements can be assigned","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/codegen.rs","lineNumber":625,"sourceCode":"                        // Generate bytecode: load base, load value, store field\n                        self.compile_expression(base);\n                        self.compile_expression_with_block_behavior(value, true);\n                        self.emit(Instruction::StoreField(field_index));\n                    }\n                    thir::Expr::ArrayAccess {base, index, meta: _} => {\n\n                        self.compile_expression(base);\n                        self.compile_expression(index);\n                        self.compile_expression_with_block_behavior(value, true);\n\n                        self.emit(match base.meta().1.as_ref().expect(\"must have a resolved type\") {\n                            TypeIR::List(_, _) => Instruction::StoreArrayElement,\n                            TypeIR::Map(_, _, _) => Instruction::StoreMapElement,\n                            _ => panic!(\"array access should be either map or array.\")\n                        });\n\n                    }\n                    _ => panic!(\"Invalid left hand of assignment, only variables, instance fields and array elements can be assigned\"),\n                }\n            }\n            thir::Statement::AssignOp {\n                left,\n                value,\n                assign_op,\n                ..\n            } => {\n                let binop = match assign_op {\n                    hir::AssignOp::AddAssign => Instruction::BinOp(BinOp::Add),\n                    hir::AssignOp::SubAssign => Instruction::BinOp(BinOp::Sub),\n                    hir::AssignOp::MulAssign => Instruction::BinOp(BinOp::Mul),\n                    hir::AssignOp::DivAssign => Instruction::BinOp(BinOp::Div),\n                    hir::AssignOp::ModAssign => Instruction::BinOp(BinOp::Mod),\n                    hir::AssignOp::BitAndAssign => Instruction::BinOp(BinOp::BitAnd),\n                    hir::AssignOp::BitOrAssign => Instruction::BinOp(BinOp::BitOr),\n                    hir::AssignOp::BitXorAssign => Instruction::BinOp(BinOp::BitXor),\n                    hir::AssignOp::ShlAssign => Instruction::BinOp(BinOp::Shl),","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/codegen.rs#L607-L643","documentation":"A panic emitted when the left-hand side of an assignment statement is not one of the supported assignable forms: a local variable, an instance field access, or an indexed element. The BAML compiler does not support other assignment targets.","triggerScenarios":"Assignment to expressions like function calls `f() = x`, literals, parenthesized complex expressions, or other unsupported LHS forms in BAML source.","commonSituations":"Ported code from other languages assuming richer assignment targets; accidentally writing `=` where `==` was intended in a condition.","solutions":["Rewrite the statement so the left side is a variable, obj.field, or collection[index]","Assign the expression result to a variable first, then use it","Check for a typo of `=` vs `==`"],"exampleFix":"// before\nfoo() = 5\n// after\nlet result = foo()\n// use result; assignment targets must be variables, fields, or elements","handlingStrategy":"validation","validationCode":"// Validate assignment target before compiling:\n// valid if Var(name) | FieldAccess{..} | Index{..}\nfn is_valid_assign_target(expr: &Expr) -> bool {\n    matches!(expr, Expr::Var(_) | Expr::FieldAccess { .. } | Expr::Index { .. })\n}","typeGuard":"fn is_assignable_target(e: &Expr) -> bool {\n    matches!(e, Expr::Var(_) | Expr::FieldAccess { .. } | Expr::Index { .. })\n}","tryCatchPattern":null,"preventionTips":["Assign only to variables, fields, or indexed elements","Double-check `=` vs `==` in conditional expressions","Expand complex assignment targets into intermediate variables"],"tags":["rust","compiler","syntax","panic"],"backgroundTag":"invalid-argument-value","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"}