{"record":{"id":"aa7e9c3daba17e60","repo":"BoundaryML/baml","slug":"array-assignment-on-non-list-value-at","errorCode":null,"errorMessage":"array assignment on non-list value at {:?}","messagePattern":"array assignment on non-list value at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":1540,"sourceCode":"                    .await?,\n                )?;\n\n                let idx = match index_value {\n                    BamlValueWithMeta::Int(i, _) if i >= 0 => i as usize,\n                    _ => bail!(\n                        \"array assignment requires a non-negative integer index at {:?}\",\n                        meta.0\n                    ),\n                };\n\n                match &mut base_value {\n                    BamlValueWithMeta::List(items, _) => {\n                        if idx >= items.len() {\n                            bail!(\"array assignment index out of bounds\");\n                        }\n                        items[idx] = value_to_assign.clone();\n                    }\n                    _ => bail!(\"array assignment on non-list value at {:?}\", meta.0),\n                }\n\n                value_to_assign = base_value;\n                current_expr = base.as_ref();\n            }\n            _ => return Err(anyhow!(\"Complex assignment targets not yet supported\")),\n        }\n    }\n}\n\nfn lookup(scopes: &[Scope], name: &str) -> Option<BamlValueWithMeta<ExprMetadata>> {\n    for s in scopes.iter().rev() {\n        if let Some(cell) = s.variables.get(name) {\n            return Some(cell.lock().unwrap().clone());\n        }\n    }\n    None\n}","sourceCodeStart":1522,"sourceCodeEnd":1558,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L1522-L1558","documentation":"Once the index of an `arr[i] = v` target is validated, the base value must be a `BamlValueWithMeta::List`. If the base is a map, string, or other kind, the interpreter bails with `array assignment on non-list value`, including the source location from `meta.0`.","triggerScenarios":"`x[i] = v` where `x` evaluates to a Map or any non-list value (e.g. trying positional assignment on a map).","commonSituations":"Confusing maps and lists in BAML; a variable holding JSON of unexpected shape (object instead of array); refactors changing a variable's type while positional writes remain.","solutions":["Confirm the base value is a list before positional assignment","Use map field-assignment syntax (`m[\"key\"] = v`) for maps instead","Parse/convert the value to a list if it arrives as another JSON shape","Add a runtime check (e.g. length or type inspection) before assigning"],"exampleFix":"// before\nlet m = {};\nm[0] = \"x\"; // non-list value\n// after\nlet m = {};\nm[\"0\"] = \"x\"; // map key assignment","handlingStrategy":"type-guard","validationCode":"// confirm the base is a list before positional assignment\nassert matches!(base, BamlValue::List(_));","typeGuard":"fn is_list(v: &BamlValue) -> bool { matches!(v, BamlValue::List(_)) }","tryCatchPattern":"// host-side\nmatch result {\n    Err(e) if e.to_string().contains(\"non-list value\") => {\n        // convert base to a list or switch to map-key assignment\n    }\n    other => other?,\n}","preventionTips":["Track value shapes through your BAML code","Validate parsed JSON has arrays where you index-assign","Avoid reusing one variable for both list and map values"],"tags":["baml","interpreter","assignment","type-mismatch"],"backgroundTag":"type-mismatch","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"}