{"record":{"id":"a4fe080b8227192c","repo":"BoundaryML/baml","slug":"unsupported-types-for-operator","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":883,"sourceCode":"                                    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                                (\n                                    BamlValueWithMeta::String(a, meta),\n                                    BamlValueWithMeta::String(b, _),\n                                ) => BamlValueWithMeta::String(format!(\"{a}{b}\"), meta),\n                                _ => 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\"),","sourceCodeStart":865,"sourceCodeEnd":901,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L865-L901","documentation":"The += compound assignment operator in the BAML interpreter only supports int+=int, float+=int, int+=float (to float), and string+=string concatenation. Any other operand type combination makes handle_statement bail with this error.","triggerScenarios":"Executing `x += y` where current x and y are not both numeric or both strings (e.g. bool, null, list, map operands).","commonSituations":"Accidentally concatenating a string with a number, or += on a variable initialized to null/bool instead of a numeric/string value.","solutions":["Cast operands to matching types before += (e.g. use string interpolation or explicit conversion).","Verify the variable being accumulated is initialized to 0, 0.0, or \"\" as appropriate.","Use explicit addition with correct types instead of compound assignment for mixed types."],"exampleFix":"// before\ncount += 0.5 // count is Int, no float+=float\n// after\nlet count = count as float; count += 0.5","handlingStrategy":"validation","validationCode":"if (!isNumber(acc) && typeof acc !== 'string') throw new Error('+= requires numeric or string operands'); if (isNumber(acc) !== isNumber(incr) && typeof acc === 'string') throw new Error('cannot += number to string');","typeGuard":"function isNumber(v) { return typeof v === 'number'; }","tryCatchPattern":"try { applyAssignOp('AddAssign', lhs, rhs); } catch (e) { if (e.message.includes('unsupported types for +=')) { /* coerce operands or report type error */ } else { throw e; } }","preventionTips":["Initialize accumulators with the correct type (0, 0.0, or \"\").","Match string concatenation with string operands only.","Cast int/float explicitly before mixing in +=."],"tags":["runtime","type-error","assignment","interpreter"],"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"}