{"record":{"id":"e5075b21c2f76a4a","repo":"pydantic/monty","slug":"loadcell-entry-is-not-a-cell","errorCode":null,"errorMessage":"LoadCell: entry is not a Cell","messagePattern":"LoadCell: entry is not a Cell","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/monty/src/bytecode/vm/mod.rs","lineNumber":2478,"sourceCode":"        if matches!(self.globals[slot as usize], Value::Undefined) {\n            let name = self.global_name(slot);\n            return Err(self.name_error(slot, name));\n        }\n        let old_value = mem::replace(&mut self.globals[slot as usize], Value::Undefined);\n        old_value.drop_with(self);\n        Ok(())\n    }\n\n    /// Loads from a closure cell and pushes onto the stack.\n    ///\n    /// The cell `HeapId` is read from the frame's local variable slot on the stack\n    /// (cells are stored as `Value::Ref(cell_id)` at known positions in the locals region).\n    /// Returns a `NameError` if the cell value is undefined (free variable not bound).\n    fn load_cell(&mut self, slot: u16) -> RunResult<()> {\n        let cell_id = self.cell_id_from_local(slot);\n        let value = match self.heap.get(cell_id) {\n            HeapData::Cell(c) => c.0.clone_with_heap(self),\n            _ => panic!(\"LoadCell: entry is not a Cell\"),\n        };\n\n        // An undefined value raises the error CPython picks by cell kind: the\n        // free-variable NameError only for a cell *captured* from an enclosing\n        // function; an unbound cell this frame owns (a local captured by\n        // nested functions) is an ordinary UnboundLocalError, like any local.\n        if matches!(value, Value::Undefined) {\n            value.drop_with(self);\n            let name = self.current_frame.code.local_name(slot);\n            Err(if self.is_free_var_slot(slot) {\n                self.free_var_error(name)\n            } else {\n                self.unbound_local_error(slot, name)\n            })\n        } else {\n            self.push(value);\n            Ok(())\n        }","sourceCodeStart":2460,"sourceCodeEnd":2496,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty/src/bytecode/vm/mod.rs#L2460-L2496","documentation":"`load_cell` reads the heap entry for a local slot's cell to push its value; this panic fires when the entry stored at `cell_id` is not a `Cell`. Cells live at known fixed slots in a frame's locals region, so a mismatch means the heap entry was replaced by another type — an interpreter invariant failure, not a Python-level exception (a genuinely unbound cell raises NameError/UnboundLocalError instead).","triggerScenarios":"Executing a `LoadCell` opcode (reading a free variable or a local captured by a nested function) when the HeapId in the local slot no longer points to a `HeapData::Cell`; only via heap corruption, an interpreter bug, or fuzzing.","commonSituations":"Fuzzing Monty (crates/fuzz string_input_panic target); hacking on closures/cell implementation in the VM; a patch that stores a non-cell Value into a cell slot or mishandles heap reuse.","solutions":["File a bug with the reproducing Python snippet — the cell HeapId points at a non-Cell heap entry","Audit code paths that write to local slots holding cells (StoreCell, frame setup) for type-tagging mistakes","Run the monty test suite plus memory-model-checks to find the refcount/drop path corrupting the entry"],"exampleFix":"// not applicable — internal interpreter bug, not a caller-fixable condition","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Not a catchable library error — treat as a bug report.\nmatch monty.run(closure_code, limits) {\n    Ok(_) => (),\n    Err(e) => report_bug_with_repro(closure_code, e),\n}","preventionTips":["Report closure/cell reproducers to maintainers","Run memory-model-checks after changing cell or frame-layout code","Avoid hand-editing heap entry tagging"],"tags":["panic","internal","heap","closures","cells"],"backgroundTag":"internal-invariant-violation","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}