{"record":{"id":"ea255f51afbc3e72","repo":"BoundaryML/baml","slug":"unsupported-types-for-operator-interpret","errorCode":null,"errorMessage":"unsupported types for -= operator","messagePattern":"unsupported types for -= operator","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":901,"sourceCode":"                                _ => bail!(\"unsupported types for += operator\"),\n                            },\n                            AssignOp::SubAssign => match (current_val.clone(), rhs_val.clone()) {\n                                (BamlValueWithMeta::Int(a, meta), BamlValueWithMeta::Int(b, _)) => {\n                                    BamlValueWithMeta::Int(a - b, meta)\n                                }\n                                (\n                                    BamlValueWithMeta::Float(a, meta),\n                                    BamlValueWithMeta::Float(b, _),\n                                ) => BamlValueWithMeta::Float(a - b, meta),\n                                (\n                                    BamlValueWithMeta::Int(a, meta),\n                                    BamlValueWithMeta::Float(b, _),\n                                ) => BamlValueWithMeta::Float((a as f64) - b, meta),\n                                (\n                                    BamlValueWithMeta::Float(a, meta),\n                                    BamlValueWithMeta::Int(b, _),\n                                ) => BamlValueWithMeta::Float(a - (b as f64), meta),\n                                _ => bail!(\"unsupported types for -= operator\"),\n                            },\n                            AssignOp::MulAssign => match (current_val.clone(), rhs_val.clone()) {\n                                (BamlValueWithMeta::Int(a, meta), BamlValueWithMeta::Int(b, _)) => {\n                                    BamlValueWithMeta::Int(a * b, meta)\n                                }\n                                (\n                                    BamlValueWithMeta::Float(a, meta),\n                                    BamlValueWithMeta::Float(b, _),\n                                ) => BamlValueWithMeta::Float(a * b, meta),\n                                (\n                                    BamlValueWithMeta::Int(a, meta),\n                                    BamlValueWithMeta::Float(b, _),\n                                ) => BamlValueWithMeta::Float((a as f64) * b, meta),\n                                (\n                                    BamlValueWithMeta::Float(a, meta),\n                                    BamlValueWithMeta::Int(b, _),\n                                ) => BamlValueWithMeta::Float(a * (b as f64), meta),\n                                _ => bail!(\"unsupported types for *= operator\"),","sourceCodeStart":883,"sourceCodeEnd":919,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L883-L919","documentation":"THIR interpreter runtime error: the `-=` compound-assign operator was applied to operand types with no supported combination. Supported pairs are int/int and float/float (with mixed numeric widening); anything else — e.g. string, bool, or null on either side — falls through to this bail during evaluation of the assignment statement.","triggerScenarios":"Executing `x -= y` where x or y is not an Int or Float at runtime.","commonSituations":"Subtracting from a variable that was assigned a string or null earlier, or attempting arithmetic on parsed values that stayed strings.","solutions":["Ensure both operands are numeric before -= (convert with explicit casts).","Check the variable's initialization to confirm it holds a number.","If subtracting numeric strings, parse them to int/float first."],"exampleFix":"// before\ntotal -= \"5\"\n// after\ntotal -= 5","handlingStrategy":"validation","validationCode":"if (!isNumber(acc) || !isNumber(rhs)) throw new Error('-= requires numeric operands');","typeGuard":"function isNumber(v) { return typeof v === 'number'; }","tryCatchPattern":"try { applyAssignOp('SubAssign', lhs, rhs); } catch (e) { if (e.message.includes('unsupported types for -=')) { /* coerce to numbers or report */ } else { throw e; } }","preventionTips":["Confirm the variable holds int/float before -=.","Parse numeric strings before arithmetic.","Avoid reusing a subtraction accumulator for other types."],"tags":["runtime","type-error","assignment","arithmetic"],"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"}