{"record":{"id":"ab6bb9b8716a04a6","repo":"BoundaryML/baml","slug":"shift-requires-integer-operands-interpret","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":1006,"sourceCode":"                                _ => 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,\n                            run_llm_function,\n                            watch_handler,\n                            function_name,\n                        )\n                        .await?;\n                        // Check for changes in watch variables after compound assignment\n                        check_watch_changes(\n                            scopes,\n                            watch_handler,","sourceCodeStart":988,"sourceCodeEnd":1024,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L988-L1024","documentation":"THIR interpreter runtime error: the `>>=` shift-assign operator was applied to non-integer operands — at least one side of the assignment is not an Int (e.g. a float, string, or bool). Shifts are only defined for integer pairs, so evaluation bails.","triggerScenarios":"Executing `x >>= y` where `x` or `y` is a Float, Bool, String, etc. — e.g. `x >>= 1.0` or shifting a string-typed value.","commonSituations":"Shift counts computed as floats (from division), bit-packing code where the packed value ended up typed as something other than Int, or values parsed from LLM output.","solutions":["Convert both operands to Int before the shift (explicit integer conversion for computed amounts).","Use integer literals for constant shift counts.","Confirm the variable being shifted is Int-typed throughout its lifetime."],"exampleFix":"// before (BAML)\nval >>= 1.0; // error: shift >>= requires integer operands\n\n// after\nval >>= 1; // Int operands","handlingStrategy":"type-guard","validationCode":"// verify both shift operands are ints before >>= executes\nfunction assertShrOperands(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 and retry, or fix the producer of the value\n  } else { throw e; }\n}","preventionTips":["Use integer literals for constant shift counts.","Convert float-computed amounts to integers explicitly before shifting.","Ensure unpacked/parsed values are Int before shifting them.","Type-check shift sites during review of bit-manipulation code."],"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"}