{"record":{"id":"c937da922a3ea076","repo":"BoundaryML/baml","slug":"undefined-field-class-name-field","errorCode":null,"errorMessage":"undefined field: {class_name}.{field}","messagePattern":"undefined field: (.+?)\\.(.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/codegen.rs","lineNumber":604,"sourceCode":"            thir::Statement::Assign { left, value, .. } => {\n                match left {\n                    thir::Expr::Var(name, _) => {\n                        self.compile_expression_with_block_behavior(value, true);\n                        self.emit(Instruction::StoreVar(self.locals[name]));\n                    }\n                    thir::Expr::FieldAccess { base, field, meta: _ } => {\n                        // Get class name from type metadata\n                        let class_name = match base.meta().1.as_ref() {\n                            Some(TypeIR::Class { name, .. }) => name,\n                            _ => panic!(\"Field access on non-class type\"),\n                        };\n\n                        // Resolve field index\n                        let Some(resolved_fields) = self.classes.get(class_name) else {\n                            panic!(\"undefined class: {class_name}\");\n                        };\n                        let Some(&field_index) = resolved_fields.get(field) else {\n                            panic!(\"undefined field: {class_name}.{field}\");\n                        };\n\n                        // 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                        });","sourceCodeStart":586,"sourceCodeEnd":622,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/codegen.rs#L586-L622","documentation":"This is a Rust panic raised during bytecode generation in the BAML compiler's codegen pass. When compiling an assignment to an instance field (obj.field = value), the compiler resolved the base's class type but the field name was not found in the class's resolved field map. It means the field name in your BAML source does not exist on the declared class.","triggerScenarios":"Compiling a BAML statement like `obj.field = value` where `field` is not a member of the class of `obj`; misspelled field name; assigning a field on the wrong class instance.","commonSituations":"Typos in BAML source; renaming a class field without updating assignments; generated code drift after class schema edits.","solutions":["Fix the field name in the BAML source to match the class definition","Check the class declaration for the exact field spelling/casing","Regenerate the IR if the class was recently edited so type metadata is fresh"],"exampleFix":"// before\nobj.nmae = \"x\"\n// after\nobj.name = \"x\"","handlingStrategy":"validation","validationCode":"fn validate_field(class_fields: &[&str], class_name: &str, field: &str) -> Result<(), String> {\n    if !class_fields.contains(&field) {\n        return Err(format!(\"field '{}' does not exist on class '{}'\", field, class_name));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep field names in assignments consistent with class declarations","Grep BAML sources for the field name after renames","Run compilation early in CI to catch field typos"],"tags":["rust","compiler","codegen","panic"],"backgroundTag":"schema-validation-failed","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"}