{"record":{"id":"6aac981c3f96b015","repo":"BoundaryML/baml","slug":"bitwise-requires-integer-operands-at-6aac98","errorCode":null,"errorMessage":"bitwise ^ requires integer operands at {:?}","messagePattern":"bitwise \\^ requires integer operands at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2508,"sourceCode":"\n        // Bitwise operations (integer only)\n        BinaryOperator::BitAnd => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Int(a & b, meta.clone())\n            }\n            _ => bail!(\"bitwise & requires integer operands at {:?}\", meta.0),\n        },\n        BinaryOperator::BitOr => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Int(a | b, meta.clone())\n            }\n            _ => bail!(\"bitwise | requires integer operands at {:?}\", meta.0),\n        },\n        BinaryOperator::BitXor => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Int(a ^ b, meta.clone())\n            }\n            _ => bail!(\"bitwise ^ requires integer operands at {:?}\", meta.0),\n        },\n        BinaryOperator::Shl => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                if b < 0 {\n                    bail!(\"negative shift amount at {:?}\", meta.0);\n                }\n                BamlValueWithMeta::Int(a << b, meta.clone())\n            }\n            _ => bail!(\"shift << requires integer operands at {:?}\", meta.0),\n        },\n        BinaryOperator::Shr => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                if b < 0 {\n                    bail!(\"negative shift amount at {:?}\", meta.0);\n                }\n                BamlValueWithMeta::Int(a >> b, meta.clone())\n            }\n            _ => bail!(\"shift >> requires integer operands at {:?}\", meta.0),","sourceCodeStart":2490,"sourceCodeEnd":2526,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2490-L2526","documentation":"THIR interpreter runtime error: the bitwise `^` (xor) operator was applied to non-integer operands. Only Int/Int is defined for bitwise ops, so any other operand pair falls through to this bail at the expression's location.","triggerScenarios":"Evaluating `a ^ b` where either operand is bool, float, string, or null — e.g. `toggle ^ 1` with a bool toggle, or XOR-ing hashed values stored as strings.","commonSituations":"Using `^` as exponentiation (as in some languages) — BAML does not define it that way; toggling bool flags with `^` instead of `!=`/`&&`/`||` logic; float inputs from JSON.","solutions":["For boolean XOR, use `(a && !b) || (!a && b)` or a comparison instead of `^`.","If exponentiation was intended, use the language's power function/multiplication, not `^`.","Coerce operands to integers explicitly before bitwise XOR."],"exampleFix":"// before (BAML)\nlet flipped = flag ^ 1;\n// after\nlet flipped = !flag;","handlingStrategy":"validation","validationCode":"// check integer operands before ^\nif (!Number.isInteger(a) || !Number.isInteger(b)) throw new Error('bitwise ^ requires integer operands');","typeGuard":"const isInt = (v) => typeof v === 'number' && Number.isInteger(v);","tryCatchPattern":"try {\n  result = evaluate(expr);\n} catch (e) {\n  if (String(e).includes('bitwise ^ requires integer operands')) {\n    // likely wanted boolean xor or exponentiation\n    result = evaluate(rewriteXor(expr));\n  } else throw e;\n}","preventionTips":["Do not use ^ for exponentiation or boolean toggling","Express boolean XOR with &&/||/! combinations","Verify operand types from external data sources before XOR"],"tags":["baml","type-mismatch","interpreter","bitwise-operator"],"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"}