{"record":{"id":"22b3138ab37c2929","repo":"tracel-ai/burn","slug":"should-be-int-got-bool","errorCode":null,"errorMessage":"Should be int, got bool","messagePattern":"Should be int, got bool","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-dispatch/src/tensor.rs","lineNumber":65,"sourceCode":"    }\n    /// Returns the inner float tensor primitive.\n    pub fn as_float(&self) -> &B::FloatTensorPrimitive {\n        match self {\n            BackendTensor::Float(tensor) => tensor,\n            BackendTensor::Int(_) => panic!(\"Should be float, got int\"),\n            BackendTensor::Bool(_) => panic!(\"Should be float, got bool\"),\n            BackendTensor::Quantized(_) => panic!(\"Should be float, got quantized\"),\n            #[cfg(feature = \"autodiff\")]\n            BackendTensor::Autodiff(_) => panic!(\"Should be float, got autodiff\"),\n        }\n    }\n\n    /// Returns the inner int tensor primitive.\n    pub fn int(self) -> B::IntTensorPrimitive {\n        match self {\n            BackendTensor::Int(tensor) => tensor,\n            BackendTensor::Float(_) => panic!(\"Should be int, got float\"),\n            BackendTensor::Bool(_) => panic!(\"Should be int, got bool\"),\n            BackendTensor::Quantized(_) => panic!(\"Should be int, got quantized\"),\n            #[cfg(feature = \"autodiff\")]\n            BackendTensor::Autodiff(_) => panic!(\"Should be int, got autodiff\"),\n        }\n    }\n\n    /// Returns the inner bool tensor primitive.\n    pub fn bool(self) -> B::BoolTensorPrimitive {\n        match self {\n            BackendTensor::Bool(tensor) => tensor,\n            BackendTensor::Float(_) => panic!(\"Should be bool, got float\"),\n            BackendTensor::Int(_) => panic!(\"Should be bool, got int\"),\n            BackendTensor::Quantized(_) => panic!(\"Should be bool, got quantized\"),\n            #[cfg(feature = \"autodiff\")]\n            BackendTensor::Autodiff(_) => panic!(\"Should be bool, got autodiff\"),\n        }\n    }\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-dispatch/src/tensor.rs#L47-L83","documentation":"BackendTensor::int() was called on a Bool tensor handle. Only the Int variant yields an int primitive, so the code panics. A boolean tensor (typically a mask or comparison result) reached a path expecting integer values.","triggerScenarios":"Calling int() on a bool tensor from comparison ops (==, <, >) or logical ops; using a bool mask where integer indices/values are required; custom code treating bools as 0/1 ints without conversion.","commonSituations":"Using a comparison result as an index directly; PyTorch-style implicit bool->int promotion assumptions; passing mask tensors into ops implemented only for int primitives.","solutions":["Convert the bool tensor to int explicitly (bool_tensor.int() via the backend cast op) before the int-only call","Confirm the upstream op actually outputs Int rather than Bool","Match the BackendTensor variant at the call site and handle Bool deliberately (e.g. where/select semantics)","Validate dtype via TensorMetadata at the boundary"],"exampleFix":"// before\nlet idx = mask_handle.int(); // panics: Bool variant\n// after\nlet idx = mask_handle.bool().int(); // explicit bool -> int cast (0/1 values)","handlingStrategy":"type-guard","validationCode":"if matches!(handle, BackendTensor::Bool(_)) {\n    let idx = handle.bool().int(); // explicit 0/1 conversion\n}","typeGuard":"fn is_int<B: BackendTypes>(t: &BackendTensor<B>) -> bool {\n    matches!(t, BackendTensor::Int(_))\n}","tryCatchPattern":null,"preventionTips":["Convert masks to ints explicitly when used as numeric values","Confirm the producing op outputs Int (comparison ops output Bool)","Never rely on implicit bool-to-int promotion"],"tags":["rust","panic","dtype-mismatch","bool"],"backgroundTag":"tensor-dtype-mismatch","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}