{"record":{"id":"b212b5b1cdc5eb4b","repo":"pydantic/monty","slug":"expected-list","errorCode":null,"errorMessage":"expected list","messagePattern":"expected list","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/monty/src/types/list.rs","lineNumber":1150,"sourceCode":"            create_heap_with_list_and_longint(vec![Value::Int(10), Value::Int(20), Value::Int(30)], BigInt::from(1));\n        let mut interns = create_test_interns();\n        let code = Code::empty();\n\n        let key = Value::Ref(index_id);\n        let new_value = Value::Int(99);\n        heap.inc_ref(index_id);\n\n        let result = HeapReader::with(&mut heap, &mut (&code, &mut interns), |reader, (code, interns)| {\n            let mut vm = VM::new(\n                Vec::new(),\n                code,\n                reader,\n                interns,\n                PrintWriter::Disabled,\n                VmEnv::default(),\n            );\n            let HeapReadOutput::List(mut list) = vm.heap.read(list_id) else {\n                panic!(\"expected list\");\n            };\n            list.py_setitem(key, new_value, &mut vm)\n        });\n\n        assert!(result.is_ok());\n\n        // Verify the list was updated by checking it matches expected Int value\n        let HeapData::List(list) = heap.get(list_id) else {\n            panic!(\"expected list\");\n        };\n        assert!(matches!(list.as_slice()[1], Value::Int(99)));\n\n        // Clean up\n        Value::Ref(list_id).drop_with(&mut heap);\n    }\n\n    /// Tests py_setitem with a negative LongInt index that fits in i64.\n    #[test]","sourceCodeStart":1132,"sourceCodeEnd":1168,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty/src/types/list.rs#L1132-L1168","documentation":"A test-helper panic in Monty's list tests: after reading a HeapId the code asserts it is a List before calling `py_setitem`. It fires only if the heap entry under test resolves to something other than a List, meaning the test fixture or heap setup is wrong. It is test code, not production behavior.","triggerScenarios":"Running the list `py_setitem` unit test (`py_setitem_longint_fits_in_i64`) when `list_id` was allocated as a non-List value or the heap read returns a different variant after test refactoring.","commonSituations":"Seen by contributors editing list tests, changing heap entry allocation in the fixture, or renaming heap variants so a fixture allocates the wrong type.","solutions":["Check that the test fixture allocates `list_id` with `HeapData::List`, not another variant.","Re-read the surrounding test to confirm list_id refers to the list, not the key or value.","Rebuild the crate (`cargo build -p monty`) to rule out stale test artifacts."],"exampleFix":"// before\nlet list_id = vm.heap.allocate(HeapData::Tuple(items), &interns)?; // wrong variant\n// after\nlet list_id = vm.heap.allocate(HeapData::List(Vec::new()), &interns)?;","handlingStrategy":"validation","validationCode":"debug_assert!(matches!(vm.heap.read(list_id), HeapReadOutput::List(_)), \"fixture must allocate a List for list_id\");","typeGuard":"fn as_list(read: &HeapReadOutput<'_>) -> Option<&HeapRead<'_, List>> {\n    match read { HeapReadOutput::List(l) => Some(l), _ => None }\n}","tryCatchPattern":null,"preventionTips":["Verify test fixtures allocate the exact HeapData variant under test.","Keep HeapId variables named clearly (list_id vs key/value ids) to avoid mix-ups.","Run the specific test binary after refactoring heap variants."],"tags":["rust","internal-error","panic","test-code","list"],"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-14T16:17:12.679Z"}