{"record":{"id":"a630ace6c984e8e8","repo":"BoundaryML/baml","slug":"shift-requires-integer-operands-at","errorCode":null,"errorMessage":"shift << requires integer operands at {:?}","messagePattern":"shift << requires integer operands at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2517,"sourceCode":"            (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),\n        },\n        BinaryOperator::InstanceOf => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Class(class, ..), BamlValueWithMeta::Class(right_class, ..)) => {\n                BamlValueWithMeta::Bool(class == right_class, meta.clone())\n            }\n            _ => bail!(\"instanceof requires class operands at {:?}\", meta.0),\n        },\n    })\n}","sourceCodeStart":2499,"sourceCodeEnd":2535,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2499-L2535","documentation":"THIR interpreter runtime error: the `<<` shift-left operator was applied to non-integer operands. Shifts require Int on both sides; evaluating with any other type combination (including float) aborts with this bail and the expression metadata.","triggerScenarios":"Evaluating `a << b` where either operand is a bool, float, string, or null — e.g. `1 << width` where width is a float from JSON, or `flags << 2` with bool flags.","commonSituations":"Shift amounts parsed from JSON/config as floats; using bools as bit values instead of 0/1 ints; string-encoded numbers not converted before shifting.","solutions":["Ensure both operands are integers; convert/round floats and parse strings first.","Replace bool operands with 0/1 integer literals.","For boolean doubling logic, use multiplication or if/else instead of `<<`."],"exampleFix":"// before (BAML)\nlet scaled = value << bitWidth; // bitWidth is float\n// after\nlet scaled = value << intBitWidth; // ensured Int","handlingStrategy":"validation","validationCode":"// check integer operands before <<\nif (!Number.isInteger(value) || !Number.isInteger(shift)) throw new Error('shift << 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('shift << requires integer operands')) {\n    result = evaluate(coerceToInts(expr));\n  } else throw e;\n}","preventionTips":["Convert float shift amounts from JSON/config to ints explicitly","Use 0/1 ints instead of bools as bit values","Add tests covering << with non-int operands"],"tags":["baml","type-mismatch","interpreter","shift-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"}