BoundaryML/baml · error

shift >>= requires integer operands

Error message

shift >>= requires integer operands

What it means

THIR interpreter runtime error: the `>>=` shift-assign operator was applied to non-integer operands — at least one side of the assignment is not an Int (e.g. a float, string, or bool). Shifts are only defined for integer pairs, so evaluation bails.

Source

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

                                _ => bail!("bitwise |= requires integer operands"),
                            },
                            AssignOp::ShlAssign => match (current_val.clone(), rhs_val.clone()) {
                                (BamlValueWithMeta::Int(a, meta), BamlValueWithMeta::Int(b, _)) => {
                                    if b < 0 {
                                        bail!("negative shift amount in <<= operator");
                                    }
                                    BamlValueWithMeta::Int(a << b, meta)
                                }
                                _ => bail!("shift <<= requires integer operands"),
                            },
                            AssignOp::ShrAssign => match (current_val.clone(), rhs_val.clone()) {
                                (BamlValueWithMeta::Int(a, meta), BamlValueWithMeta::Int(b, _)) => {
                                    if b < 0 {
                                        bail!("negative shift amount in >>= operator");
                                    }
                                    BamlValueWithMeta::Int(a >> b, meta)
                                }
                                _ => bail!("shift >>= requires integer operands"),
                            },
                        };

                        // Assign the result back to the target expression
                        assign_to_expr(
                            left,
                            result_val,
                            scopes,
                            thir,
                            run_llm_function,
                            watch_handler,
                            function_name,
                        )
                        .await?;
                        // Check for changes in watch variables after compound assignment
                        check_watch_changes(
                            scopes,
                            watch_handler,

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Convert both operands to Int before the shift (explicit integer conversion for computed amounts).
  2. Use integer literals for constant shift counts.
  3. Confirm the variable being shifted is Int-typed throughout its lifetime.

Example fix

// before (BAML)
val >>= 1.0; // error: shift >>= requires integer operands

// after
val >>= 1; // Int operands
Defensive patterns

Strategy: type-guard

Validate before calling

// verify both shift operands are ints before >>= executes
function assertShrOperands(value: unknown, amount: unknown): void {
  if (!Number.isInteger(value) || !Number.isInteger(amount)) {
    throw new Error("shift >>= requires integer operands in BAML");
  }
}

Type guard

const isInt = (v: unknown): v is number => typeof v === "number" && Number.isInteger(v);

Try / catch

try {
  await runBaml(program);
} catch (e) {
  if (String(e).includes("shift >>= requires integer operands")) {
    // convert operands to Int and retry, or fix the producer of the value
  } else { throw e; }
}

Prevention

When it happens

Trigger: Executing `x >>= y` where `x` or `y` is a Float, Bool, String, etc. — e.g. `x >>= 1.0` or shifting a string-typed value.

Common situations: Shift counts computed as floats (from division), bit-packing code where the packed value ended up typed as something other than Int, or values parsed from LLM output.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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