BoundaryML/baml · error
bitwise &= requires integer operands
Error message
bitwise &= requires integer operands
What it means
Raised by the BAML interpreter when evaluating `x &= y`. Bitwise and-assign is only implemented for Int/Int operands; any other combination of BamlValue variants falls through to this bail. It enforces BAML's integer-only bitwise operator semantics.
Source
Thrown at engine/baml-compiler/src/thir/interpret.rs:981
}
_ => bail!("unsupported types for %= operator"),
},
AssignOp::BitXorAssign => {
match (current_val.clone(), rhs_val.clone()) {
(
BamlValueWithMeta::Int(a, meta),
BamlValueWithMeta::Int(b, _),
) => BamlValueWithMeta::Int(a ^ b, meta),
_ => bail!("bitwise ^= requires integer operands"),
}
}
AssignOp::BitAndAssign => {
match (current_val.clone(), rhs_val.clone()) {
(
BamlValueWithMeta::Int(a, meta),
BamlValueWithMeta::Int(b, _),
) => BamlValueWithMeta::Int(a & b, meta),
_ => bail!("bitwise &= requires integer operands"),
}
}
AssignOp::BitOrAssign => match (current_val.clone(), rhs_val.clone()) {
(BamlValueWithMeta::Int(a, meta), BamlValueWithMeta::Int(b, _)) => {
BamlValueWithMeta::Int(a | b, meta)
}
_ => 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()) {View on GitHub (pinned to bd85ce9dee)
Solutions
- Make both operands Int before `&=` (explicitly convert bools/floats).
- For bool conjunction use `&&` / `flag = flag && other` instead of `&=`.
- Check where the mask value originates and fix its declared type to Int.
Example fix
// before (BAML) let mask = 0.75; flags &= mask; // error: bitwise &= requires integer operands // after let mask = 0b0110; flags &= mask; // Int operands
Defensive patterns
Strategy: type-guard
Validate before calling
// validate mask/flags are ints before &= executes
function assertAndOperands(flags: unknown, mask: unknown): void {
if (!Number.isInteger(flags) || !Number.isInteger(mask)) {
throw new Error("bitwise &= 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("bitwise &= requires integer operands")) {
// coerce mask to Int or switch to logical && and retry
} else { throw e; }
} Prevention
- Keep bitmasks in dedicated Int variables with Int defaults (0).
- Validate config/LLM-sourced mask values are integers before use.
- Use `&&` for boolean conjunction instead of `&=`.
- Grep BAML programs for `&=` during code review.
When it happens
Trigger: Executing `flags &= mask` where `flags` or `mask` is not an Int at runtime — e.g. a float bitfield, a string, or a bool used as a bit.
Common situations: Bitmask-style code where the mask was computed as a float or read from config/LLM output as a non-int type; also bool-as-bit habits from other languages.
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
- bitwise ^= requires integer operands
- bitwise |= requires integer operands
- shift <<= requires integer operands
- shift >>= requires integer operands
- shift >> requires integer operands at {:?}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/8bc2625880a1d032.
Report an issue: GitHub.