{"record":{"id":"81601431b6556a97","repo":"BoundaryML/baml","slug":"shift-requires-integer-operands","errorCode":null,"errorMessage":"shift <<= requires integer operands","messagePattern":"shift <<= requires integer operands","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":997,"sourceCode":"                                        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\"),\n                            },\n                        };\n\n                        // Assign the result back to the target expression\n                        assign_to_expr(\n                            left,\n                            result_val,\n                            scopes,\n                            thir,","sourceCodeStart":979,"sourceCodeEnd":1015,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L979-L1015","documentation":"Raised by the BAML interpreter when evaluating `x <<= y` where either operand is not an Int. Left-shift-assign is implemented only for the Int/Int pair; all other type combinations fall through to this bail.","triggerScenarios":"Executing `x <<= y` where `x` or `y` is a Float, Bool, String, etc. — e.g. shifting by a float amount `x <<= 2.0` or shifting a non-int value.","commonSituations":"Shift amounts computed from float math (division results), or literals written as `2.0` out of habit; also shifting values parsed from LLM output as strings.","solutions":["Ensure both operands are Int; round/convert float shift amounts with an explicit integer conversion.","Use integer literals without decimal points for constant shifts.","Verify the shifted variable itself holds an Int."],"exampleFix":"// before (BAML)\nx <<= steps / 2; // error if result is float: shift <<= requires integer operands\n\n// after\nx <<= toInt(steps / 2); // ensure Int operands","handlingStrategy":"type-guard","validationCode":"// verify both shift operands are ints before <<= executes\nfunction assertShlOperands(value: unknown, amount: unknown): void {\n  if (!Number.isInteger(value) || !Number.isInteger(amount)) {\n    throw new Error(\"shift <<= 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(\"shift <<= requires integer operands\")) {\n    // convert operands to Int (round computed amounts) and retry\n  } else { throw e; }\n}","preventionTips":["Write constant shift amounts as integer literals (`1`, not `1.0`).","Convert division-derived shift amounts to integers explicitly.","Keep shifted variables Int-typed end to end.","Check operand types whenever shift code is refactored."],"tags":["baml","interpreter","bitwise","shift","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"}