{"record":{"id":"8e51e9965c1a699b","repo":"BoundaryML/baml","slug":"undefined-enum-name","errorCode":null,"errorMessage":"undefined enum: {name}","messagePattern":"undefined enum: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/codegen.rs","lineNumber":1158,"sourceCode":"                self.emit(\n                    match base.meta().1.as_ref().expect(\"must have a resolved type\") {\n                        TypeIR::List(_, _) => Instruction::LoadArrayElement,\n                        TypeIR::Map(_, _, _) => Instruction::LoadMapElement,\n                        _ => panic!(\"array access should be either map or array.\"),\n                    },\n                );\n            }\n\n            thir::Expr::FieldAccess { base, field, .. } => {\n                // Direct enum access: Share.Rectangle\n                if let thir::Expr::Var(name, _) = base.as_ref() {\n                    if let Some(enm) = self.enums.get(name) {\n                        let Some(variant_index) = enm.get(field) else {\n                            panic!(\"undefined enum variant: {name}.{field}\");\n                        };\n\n                        let Some(enum_index) = self.globals.get(name) else {\n                            panic!(\"undefined enum: {name}\");\n                        };\n\n                        let const_index = self.add_constant(Value::Int(*variant_index as i64));\n                        self.emit(Instruction::LoadConst(const_index));\n\n                        let allocation_instruction =\n                            self.emit(Instruction::AllocVariant(ObjectIndex::from_raw(usize::MAX)));\n\n                        // TODO: Confusing name because of class alloc reuse.\n                        self.class_alloc_patch_list.push(AllocInstancePatch {\n                            location: allocation_instruction,\n                            global: *enum_index,\n                        });\n\n                        return;\n                    }\n                }\n","sourceCodeStart":1140,"sourceCodeEnd":1176,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/codegen.rs#L1140-L1176","documentation":"Panic when compiling an enum member access `EnumName.Variant`: the variant itself resolved (it exists in `self.enums`), but the enum's name is missing from the globals table, so codegen cannot emit the `LoadGlobal` needed to materialize the enum type at runtime. This indicates enum registration and the globals table are inconsistent across compiler phases.","triggerScenarios":"Compiling `Expr::FieldAccess` on a base `Var(name)` where `self.enums` contains `name` but `self.globals.get(name)` is None — the enum was collected during resolution but never registered as a global before codegen.","commonSituations":"Enums defined dynamically or in files not added to the global registry; partial compilation where some declarations were skipped; compiler bugs where enum collection and global registration use different visibility rules.","solutions":["Verify the enum is declared/imported in the same compilation unit so it gets registered as a global","Reorder or re-register declarations so the enum is registered before expressions referencing it are compiled","Check for duplicate definitions or shadowing that suppress global registration","If the enum is plainly declared, report a compiler bug: globals registration missed the enum"],"exampleFix":"// before\n// enum Share { ... } defined in another file, not imported\nlet s = Share.Rectangle\n// after\nimport \"./share.baml\"  // brings enum Share into the unit\nlet s = Share.Rectangle","handlingStrategy":"validation","validationCode":"// Ensure enums referenced via member access are registered in the compile unit\nfn ensure_enum_registered(unit: &Unit, enum_name: &str) -> Result<(), String> {\n    if unit.enums.contains_key(enum_name) && unit.globals.contains_key(enum_name) { Ok(()) }\n    else { Err(format!(\"enum `{enum_name}` is not registered in this compilation unit\")) }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Import files that define enums you reference","Do a full rebuild after adding new enum files to avoid stale registration","Check import lists whenever a member access like `Enum.Variant` fails"],"tags":["compiler","codegen","panic","enum","globals"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}