{"record":{"id":"da1736940fd4cc13","repo":"BoundaryML/baml","slug":"ntypeargs-fits-in-u16","errorCode":null,"errorMessage":"ntypeargs fits in u16","messagePattern":"ntypeargs fits in u16","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_compiler2_emit/src/emit.rs","lineNumber":1963,"sourceCode":"        {\n            // Stack layout mirrors `VirtualCall`: receiver, then the method-level\n            // type args, then the interface type (each resolved against the frame\n            // by `LoadType`), then the method name — the opcode pops in reverse.\n            self.emit_operand_pull(receiver);\n            for template in type_args {\n                let const_idx =\n                    self.add_constant(ConstValue::Type(bex_vm_types::anchor_template(template)));\n                let inst = self.emit(Instruction::LoadType(const_idx));\n                self.set_operand(inst, OperandMeta::Const(template.to_string()));\n            }\n            let iface_const = self.add_constant(ConstValue::Type(bex_vm_types::anchor_template(\n                &iface.to_template(),\n            )));\n            let inst = self.emit(Instruction::LoadType(iface_const));\n            self.set_operand(inst, OperandMeta::Const(iface.to_string()));\n            self.emit_constant(&Constant::String(method.clone()));\n            let inst = self.emit(Instruction::MakeVirtualBoundMethod {\n                ntypeargs: u16::try_from(type_args.len()).expect(\"ntypeargs fits in u16\"),\n            });\n            self.set_operand(inst, OperandMeta::Callable(method.clone()));\n            return;\n        }\n        if let Rvalue::MakeVirtualFunction {\n            self_ty,\n            iface,\n            method,\n            type_args,\n        } = rvalue\n        {\n            // Stack layout mirrors `MakeVirtualBoundMethod` with the `Self`\n            // TYPE in the receiver's slot: `Self`, then the method-level type\n            // args (already `Object::Type` OPERANDS — every one of them a\n            // `LoadType` temp, a scoped `type T = …` slot included),\n            // then the interface type, then the method name — the opcode pops\n            // in reverse.\n            let self_const =","sourceCodeStart":1945,"sourceCodeEnd":1981,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_compiler2_emit/src/emit.rs#L1945-L1981","documentation":"When emitting MakeVirtualBoundMethod, the count of type_args for the virtual bound method must fit the instruction's u16 ntypeargs field; try_from().expect enforces this as a compiler-internal invariant. Surpassing 65535 type args indicates a bug, not a user-facing condition.","triggerScenarios":"emit.rs emitting MakeVirtualBoundMethod for an interface/type-args list longer than u16::MAX (type_args.len() > 65535).","commonSituations":"Only via compiler bugs or enormous generated type-argument lists; unreachable in realistic hand-written code.","solutions":["File a compiler bug with the minimizing repro; reduce the number of type arguments on the virtual bound method","Inspect type_args construction for accidental duplication in the emitter","Refactor the interface/method into smaller parameterized pieces as a workaround"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let ntypeargs = u16::try_from(type_args.len())\n    .map_err(|_| anyhow!(\"too many type args for MakeVirtualBoundMethod: {}\", type_args.len()))?;","preventionTips":["Report any occurrence as a compiler bug with a repro","Limit generated virtual-method type-argument counts","Check type_args assembly for duplicated entries","Add emitter tests covering large type-arg lists"],"tags":["compiler","internal","overflow","emit"],"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"}