{"record":{"id":"87411fc5f402461a","repo":"BoundaryML/baml","slug":"bitwise-requires-integer-operands-87411f","errorCode":null,"errorMessage":"bitwise |= requires integer operands","messagePattern":"bitwise \\|= requires integer operands","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":988,"sourceCode":"                                        BamlValueWithMeta::Int(b, _),\n                                    ) => BamlValueWithMeta::Int(a ^ b, meta),\n                                    _ => bail!(\"bitwise ^= requires integer operands\"),\n                                }\n                            }\n                            AssignOp::BitAndAssign => {\n                                match (current_val.clone(), rhs_val.clone()) {\n                                    (\n                                        BamlValueWithMeta::Int(a, meta),\n                                        BamlValueWithMeta::Int(b, _),\n                                    ) => BamlValueWithMeta::Int(a & b, meta),\n                                    _ => bail!(\"bitwise &= requires integer operands\"),\n                                }\n                            }\n                            AssignOp::BitOrAssign => match (current_val.clone(), rhs_val.clone()) {\n                                (BamlValueWithMeta::Int(a, meta), BamlValueWithMeta::Int(b, _)) => {\n                                    BamlValueWithMeta::Int(a | b, meta)\n                                }\n                                _ => bail!(\"bitwise |= requires integer operands\"),\n                            },\n                            AssignOp::ShlAssign => match (current_val.clone(), rhs_val.clone()) {\n                                (BamlValueWithMeta::Int(a, meta), BamlValueWithMeta::Int(b, _)) => {\n                                    if b < 0 {\n                                        bail!(\"negative shift amount in <<= operator\");\n                                    }\n                                    BamlValueWithMeta::Int(a << b, meta)\n                                }\n                                _ => bail!(\"shift <<= requires integer operands\"),\n                            },\n                            AssignOp::ShrAssign => match (current_val.clone(), rhs_val.clone()) {\n                                (BamlValueWithMeta::Int(a, meta), BamlValueWithMeta::Int(b, _)) => {\n                                    if b < 0 {\n                                        bail!(\"negative shift amount in >>= operator\");\n                                    }\n                                    BamlValueWithMeta::Int(a >> b, meta)\n                                }\n                                _ => bail!(\"shift >>= requires integer operands\"),","sourceCodeStart":970,"sourceCodeEnd":1006,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L970-L1006","documentation":"Raised by the BAML interpreter when evaluating `x |= y`. Bitwise or-assign supports only Int/Int operand pairs; anything else falls through to this bail. It enforces strict integer-only semantics for bitwise assignment in BAML.","triggerScenarios":"Executing `flags |= bit` where `flags` or `bit` is a Float, Bool, String, or other non-Int value at runtime, e.g. `enabled |= true`.","commonSituations":"Flag-accumulation code where a default was set to `false` (Bool) instead of `0` (Int), or option values coming from LLM output typed as strings.","solutions":["Initialize flag variables as Int (0/1), not Bool, when using `|=`.","Convert bool operands explicitly to 0/1 before or-assigning.","Verify the right-hand side value's type from its producer (config, LLM parse) is Int."],"exampleFix":"// before (BAML)\nlet opts = false;\nopts |= needsFlag; // error: bitwise |= requires integer operands\n\n// after\nlet opts = 0;\nopts |= if needsFlag { 1 } else { 0 };","handlingStrategy":"type-guard","validationCode":"// ensure flag-accumulation operands are ints before |= runs\nfunction assertOrOperands(acc: unknown, bit: unknown): void {\n  if (!Number.isInteger(acc) || !Number.isInteger(bit)) {\n    throw new Error(\"bitwise |= requires integer operands in BAML\");\n  }\n}","typeGuard":"const isInt = (v: unknown): v is number => typeof v === \"number\" && Number.isInteger(v);","tryCatchPattern":"try {\n  await runBaml(program);\n} catch (e) {\n  if (String(e).includes(\"bitwise |= requires integer operands\")) {\n    // re-initialize flags as Int (0/1) or map bools to 0/1 and retry\n  } else { throw e; }\n}","preventionTips":["Initialize option/flag accumulators as `0` (Int), not `false` (Bool).","Map all boolean inputs to 0/1 at the boundary before bit-accumulation.","Never pipe LLM-parsed strings into `|=` without integer validation.","Review all `|=` sites for operand provenance."],"tags":["baml","interpreter","bitwise","type-mismatch"],"backgroundTag":"unsupported-operation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}