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. Only int/int and float/float (plus mixed numeric widening) are defined; any other operand types reach this bail while evaluating the assignment.

Solutions

  1. Ensure both operands are numeric (int or float) before *=.
  2. Convert string numerics with explicit parsing/casting.
  3. Verify the accumulator variable is initialized to a number (typically 1 for products).

Example fix

// before
product *= "2"
// after
product *= 2
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('MulAssign', 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: Multiplying a count by a string numeric literal, or *= on a variable accidentally holding null/bool.

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/06c592e5eb6be120. Report an issue: GitHub.

Appendix: source

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

                                _ => 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"),
                            },
                            AssignOp::DivAssign => match (current_val.clone(), rhs_val.clone()) {
                                (BamlValueWithMeta::Int(a, meta), BamlValueWithMeta::Int(b, _)) => {
                                    if b == 0 {
                                        bail!("division by zero in /= operator");
                                    }
                                    BamlValueWithMeta::Float((a as f64) / (b as f64), meta)
                                }
                                (
                                    BamlValueWithMeta::Float(a, meta),
                                    BamlValueWithMeta::Float(b, _),
                                ) => {
                                    if b == 0.0 {
                                        bail!("division by zero in /= operator");
                                    }
                                    BamlValueWithMeta::Float(a / b, meta)
                                }
                                (

View on GitHub (pinned to bd85ce9dee)