{"record":{"id":"42e1e13be5d5d235","repo":"BoundaryML/baml","slug":"expected-jump-instruction-at-index-instruction-idx","errorCode":null,"errorMessage":"expected jump instruction at index {instruction_idx}","messagePattern":"expected jump instruction at index (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"baml_language/crates/baml_compiler2_emit/src/emit.rs","lineNumber":2770,"sourceCode":"                self.bytecode.instructions[instruction_idx] = Instruction::PopJumpIfFalse(offset);\n            }\n            Instruction::JumpIfFalse(_) => {\n                self.bytecode.instructions[instruction_idx] = Instruction::JumpIfFalse(offset);\n            }\n            Instruction::PopJumpIfTrue(_) => {\n                self.bytecode.instructions[instruction_idx] = Instruction::PopJumpIfTrue(offset);\n            }\n            Instruction::JumpIfFalseOrPop(_) => {\n                self.bytecode.instructions[instruction_idx] = Instruction::JumpIfFalseOrPop(offset);\n            }\n            Instruction::JumpIfTrueOrPop(_) => {\n                self.bytecode.instructions[instruction_idx] = Instruction::JumpIfTrueOrPop(offset);\n            }\n            Instruction::JumpIfNotNullOrPop(_) => {\n                self.bytecode.instructions[instruction_idx] =\n                    Instruction::JumpIfNotNullOrPop(offset);\n            }\n            _ => panic!(\"expected jump instruction at index {instruction_idx}\"),\n        }\n    }\n\n    /// Patch all pending jump tables with actual offsets.\n    #[allow(clippy::cast_possible_wrap)]\n    fn patch_jump_tables(&mut self) {\n        for pending in std::mem::take(&mut self.pending_jump_tables) {\n            let jump_table_pc = pending.jump_table_pc;\n            let mut table = pending.table;\n\n            // Patch each arm's offset\n            for (value, target) in &pending.arms {\n                let target_pc = self.resolve_pending_target_pc(*target);\n                let offset = target_pc as isize - jump_table_pc as isize;\n                table.set(*value, offset);\n            }\n\n            // Patch default offset","sourceCodeStart":2752,"sourceCodeEnd":2788,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_compiler2_emit/src/emit.rs#L2752-L2788","documentation":"Panic in the jump-patching helper: after computing a jump offset, the instruction at instruction_idx in the bytecode array is not one of the recognized jump variants, so the replacement match falls through to a panic. This means the emitter patched an index that no longer holds a placeholder jump instruction — typically index drift between where a jump was emitted and where it is patched.","triggerScenarios":"Calling the patch routine with an instruction_idx whose bytecode slot holds a non-jump instruction, e.g. after another pass inserted or reordered instructions without updating recorded jump indices.","commonSituations":"Compiler development scenario: adding a new Instruction variant or an emitting step that shifts instructions, leaving stale patch indices.","solutions":["Update the patch routine's match arms to include the new jump instruction variant that was emitted.","Ensure every instruction insertion/emission keeps recorded jump indices in sync with the bytecode array.","Verify which instruction actually sits at instruction_idx when the panic fires and fix the emitter bookkeeping accordingly.","Report the reproducible BAML source as a compiler bug."],"exampleFix":"// before: match missing the new variant\n_ => panic!(\"expected jump instruction at index {instruction_idx}\"),\n// after: handle the variant\nInstruction::JumpIfFalseOrPop(_) => {\n    self.bytecode.instructions[instruction_idx] = Instruction::JumpIfFalseOrPop(offset);\n}","handlingStrategy":"validation","validationCode":"fn is_jump_instruction(inst: &Instruction) -> bool {\n    matches!(inst,\n        Instruction::Jump(_) | Instruction::JumpIfTrueOrPop(_) |\n        Instruction::JumpIfFalseOrPop(_) | Instruction::JumpIfNotNullOrPop(_))\n}","typeGuard":null,"tryCatchPattern":"// compiler panic — catch at the build-tool boundary\nmatch baml_cli_compile(file) {\n    Err(_) => report_bug_with_minimal_repro(),\n    Ok(_) => {}\n}","preventionTips":["Keep the patch routine's match arms in sync with all jump Instruction variants","Update patch indices whenever instructions are inserted or reordered","Use an enum wrapping (index, expected-variant) pairs for pending jumps","Run bytecode round-trip tests after adding new jump instructions"],"tags":["compiler","bytecode","panic","rust"],"backgroundTag":"internal-invariant-violation","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"}