BoundaryML/baml · error

unsupported types for -= operator

Error message

unsupported types for -= operator

What it means

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.

Solutions

  1. Ensure both operands are numeric before -= (convert with explicit casts).
  2. Check the variable's initialization to confirm it holds a number.
  3. If subtracting numeric strings, parse them to int/float first.

Example fix

// before
total -= "5"
// after
total -= 5
Defensive patterns

Strategy: validation

Validate before calling

if (!isNumber(acc) || !isNumber(rhs)) throw new Error('-= requires numeric operands');

Type guard

function isNumber(v) { return typeof v === 'number'; }

Try / catch

try { applyAssignOp('SubAssign', lhs, rhs); } catch (e) { if (e.message.includes('unsupported types for -=')) { /* coerce to numbers or report */ } else { throw e; } }

Prevention

When it happens

Trigger: Executing `x -= y` where x or y is not an Int or Float at runtime.

Common situations: Subtracting from a variable that was assigned a string or null earlier, or attempting arithmetic on parsed values that stayed strings.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/ea255f51afbc3e72. Report an issue: GitHub.

Appendix: source

Thrown at engine/baml-compiler/src/thir/interpret.rs:901

                                _ => bail!("unsupported types for += operator"),
                            },
                            AssignOp::SubAssign => match (current_val.clone(), rhs_val.clone()) {
                                (BamlValueWithMeta::Int(a, meta), BamlValueWithMeta::Int(b, _)) => {
                                    BamlValueWithMeta::Int(a - b, meta)
                                }
                                (
                                    BamlValueWithMeta::Float(a, meta),
                                    BamlValueWithMeta::Float(b, _),
                                ) => BamlValueWithMeta::Float(a - b, meta),
                                (
                                    BamlValueWithMeta::Int(a, meta),
                                    BamlValueWithMeta::Float(b, _),
                                ) => BamlValueWithMeta::Float((a as f64) - b, meta),
                                (
                                    BamlValueWithMeta::Float(a, meta),
                                    BamlValueWithMeta::Int(b, _),
                                ) => BamlValueWithMeta::Float(a - (b as f64), meta),
                                _ => bail!("unsupported types for -= operator"),
                            },
                            AssignOp::MulAssign => match (current_val.clone(), rhs_val.clone()) {
                                (BamlValueWithMeta::Int(a, meta), BamlValueWithMeta::Int(b, _)) => {
                                    BamlValueWithMeta::Int(a * b, meta)
                                }
                                (
                                    BamlValueWithMeta::Float(a, meta),
                                    BamlValueWithMeta::Float(b, _),
                                ) => BamlValueWithMeta::Float(a * b, meta),
                                (
                                    BamlValueWithMeta::Int(a, meta),
                                    BamlValueWithMeta::Float(b, _),
                                ) => BamlValueWithMeta::Float((a as f64) * b, meta),
                                (
                                    BamlValueWithMeta::Float(a, meta),
                                    BamlValueWithMeta::Int(b, _),
                                ) => BamlValueWithMeta::Float(a * (b as f64), meta),
                                _ => bail!("unsupported types for *= operator"),

View on GitHub (pinned to bd85ce9dee)