{"record":{"id":"ce05e667ee6d1156","repo":"BoundaryML/baml","slug":"bitwise-requires-integer-operands-at-interpret","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":2502,"sourceCode":"            BamlValueWithMeta::Bool(false, _) => match right_val.clone() {\n                BamlValueWithMeta::Bool(b, _) => BamlValueWithMeta::Bool(b, meta.clone()),\n                _ => bail!(\"right operand of || must be bool at {:?}\", meta.0),\n            },\n            _ => bail!(\"left operand of || must be bool at {:?}\", meta.0),\n        },\n\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, _)) => {","sourceCodeStart":2484,"sourceCodeEnd":2520,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2484-L2520","documentation":"THIR interpreter runtime error: the bitwise `|` operator was applied to non-integer operands. Bitwise operations in BAML are defined only for Int/Int; a float, string, bool, or null operand on either side reaches this bail during evaluation of the binary expression.","triggerScenarios":"Evaluating `a | b` with a bool, float, string, or null operand — e.g. combining flag enums stored as bools, or `mask | 4` where mask is a float.","commonSituations":"Using single `|` where `||` was intended for boolean OR; enum-like flag values decoded from JSON as floats; string masks from configuration.","solutions":["Use `||` for logical OR of booleans; reserve `|` for integer bitmasks.","Convert floats to ints explicitly before bitwise OR.","Ensure flag values from config/LLM output are parsed as integers."],"exampleFix":"// before (BAML)\nlet merged = allowRead | allowWrite;\n// after\nlet merged = allowRead || allowWrite;","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    result = evaluate(expr.replace(' | ', ' || '));\n  } else throw e;\n}","preventionTips":["Reserve | for bitmask merging of ints","Convert bool flags to 0/1 before combining into masks","Validate mask values parsed from external data are integers"],"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"}