{"record":{"id":"920618c6ea07211d","repo":"BoundaryML/baml","slug":"map-set-should-be-dispatched-via-glue-set","errorCode":null,"errorMessage":"Map.set: should be dispatched via __glue_set","messagePattern":"Map\\.set: should be dispatched via __glue_set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm/src/package_baml/map.rs","lineNumber":60,"sourceCode":"        let result: NativeFunctionResult = (|| {\n            let key_as_string = vm.as_string(&args[1])?.clone();\n            let value = args[2];\n            let mut map = vm.as_map_mut(&args[0])?;\n            // `IndexMap::insert` returns `Some(prev)` if the key already\n            // existed, `None` otherwise — exactly the V? semantics we want.\n            Ok(match map.insert(key_as_string, value) {\n                Some(prev) => prev,\n                None => Value::NULL,\n            })\n        })();\n        match result {\n            Ok(v) => NativeCallResult::Done(v),\n            Err(e) => NativeCallResult::Error(e),\n        }\n    }\n\n    fn set(_map: &mut IndexMap<BexStr, Value>, _key: &Value, _value: &Value) -> Option<Value> {\n        unreachable!(\"Map.set: should be dispatched via __glue_set\")\n    }\n\n    fn get(vm: &BexVm, map: MapView<'_>, key: &Value) -> Option<Value> {\n        if let Ok(k) = vm.as_string(key) {\n            map.get(k.as_str()).copied()\n        } else {\n            None\n        }\n    }\n\n    // ── delete ────────────────────────────────────────────────────────────────\n\n    fn __glue_delete(vm: &mut BexVm, args: &[Value]) -> NativeCallResult {\n        let result: NativeFunctionResult = (|| {\n            let key_as_string = vm.as_string(&args[1])?.clone();\n            let mut map = vm.as_map_mut(&args[0])?;\n            // `shift_remove` preserves the order of remaining entries (matching\n            // insertion order) — important since `keys()` / `values()` return","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm/src/package_baml/map.rs#L42-L78","documentation":"`Map.set` in the BAML map package is a placeholder that always panics: mutation of maps must go through the `__glue_set` native glue method, which holds the VM borrow needed to write into the map. The direct `set` binding exists only to satisfy the native-function table shape; calling it directly is a dispatch bug.","triggerScenarios":"The VM's method dispatch table routes `Map.set` to the raw `set` function instead of `__glue_set`, typically due to a misregistered native method name in the map package registration code.","commonSituations":"VM development or patches that alter the map package registration; custom glue dispatch layers that call native functions by name without applying the __glue_ prefix rules.","solutions":["Fix the dispatch table so `Map.set` resolves to `__glue_set`.","In BAML code, use map mutation syntax (map[key] = value) rather than any direct native call path.","Rebuild/upgrade bex_vm if a released build shows this panic."],"exampleFix":"// before\n\"set\" => NativeFn::Raw(map::set),\n// after\n\"set\" => NativeFn::Glue(map::__glue_set),","handlingStrategy":"validation","validationCode":"// Dispatch-table sanity check at map package registration:\nassert!(dispatch_table.get(\"set\") == Some(&NativeFn::Glue(map::__glue_set)));","typeGuard":null,"tryCatchPattern":"// Panics are not catchable in Rust; verify registration in a startup unit test.","preventionTips":["Route all Map mutations through __glue_* native methods.","Add a registration test asserting each map method maps to its __glue_ implementation.","Never call raw placeholder native functions directly."],"tags":["rust","map","dispatch","panic"],"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-23T08:17:48.524Z"}