{"record":{"id":"ee2ad784a4f4c19f","repo":"wasmerio/wasmer","slug":"cannot-get-size-of-reference-type","errorCode":null,"errorMessage":"Cannot get size of reference type","messagePattern":"Cannot get size of reference type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/wasix/src/syscalls/wasix/closure_prepare.rs","lineNumber":51,"sourceCode":"        let wasix_type = WasmValueType::try_from(value).map_err(|_| Errno::Inval)?;\n        match wasix_type {\n            WasmValueType::I32 => Ok(Self::I32),\n            WasmValueType::I64 => Ok(Self::I64),\n            WasmValueType::F32 => Ok(Self::F32),\n            WasmValueType::F64 => Ok(Self::F64),\n            WasmValueType::V128 => Ok(Self::V128),\n            _ => Err(Errno::Inval),\n        }\n    }\n    fn size(&self) -> u64 {\n        match self {\n            Self::I32 => 4,\n            Self::I64 => 8,\n            Self::F32 => 4,\n            Self::F64 => 8,\n            Self::V128 => 16,\n            // Not supported in closures.\n            Self::Ref(_) => panic!(\"Cannot get size of reference type\"),\n        }\n    }\n    fn store(&self, sink: &mut InstructionSink<'_>, offset: u64, memory_index: u32) {\n        match self {\n            Self::I32 => sink.i32_store(MemArg {\n                offset,\n                align: 0,\n                memory_index,\n            }),\n            Self::I64 => sink.i64_store(MemArg {\n                offset,\n                align: 0,\n                memory_index,\n            }),\n            Self::F32 => sink.f32_store(MemArg {\n                offset,\n                align: 0,\n                memory_index,","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/wasix/src/syscalls/wasix/closure_prepare.rs#L33-L69","documentation":"`size` on the closure parameter/result value wrapper returns the in-memory byte width of a value so `closure_prepare` can lay out the call frame. Reference types (`Self::Ref(_)`) are explicitly not supported in WASIX closures, and their width is undefined for this ABI, so the code panics with this message.","triggerScenarios":"Preparing a dynamic closure (`closure_prepare`) whose signature includes a reference-typed parameter or result (externref/funcref/exceptionref), causing the size computation to hit the `Ref` arm.","commonSituations":"Guest modules compiled with reference-types enabled declaring closures over ref-taking functions; code generators emitting closure descriptors from raw function types without filtering refs; ABI drift where newer module types include refs the runtime closure path doesn't support.","solutions":["Change the closure's function signature to use only scalar types (i32/i64/f32/f64/v128)","Replace reference arguments with i32 handles into a host or guest side table","Filter or reject ref-typed signatures when building closure descriptors before calling `closure_prepare`","Recompile the guest module with reference-types disabled or with a closure ABI that maps refs to indices"],"exampleFix":"// before: closure over (externref) -> i32\nlet types = vec![ClosureType::Ref(RefType::Extern)];\n// after: pass an index instead\nlet types = vec![ClosureType::I32];","handlingStrategy":"validation","validationCode":"// Before closure_prepare, reject ref-typed signatures\nif types.iter().any(|t| matches!(t, ClosureType::Ref(_))) {\n    return Err(\"reference types are not supported in closures\".into());\n}","typeGuard":"fn closure_sig_is_scalar(types: &[ClosureType]) -> bool {\n    types.iter().all(|t| !matches!(t, ClosureType::Ref(_)))\n}","tryCatchPattern":"let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| param.size()));\nif result.is_err() { /* ref param detected: remap to an i32 handle and retry */ }","preventionTips":["Build closure descriptors only from scalar-typed functions","Replace ref params with i32 side-table handles at codegen time","Add a CI type scan that flags ref-typed closures","Compile guests with reference-types disabled for closure-heavy workloads"],"tags":["wasix","closures","reference-types","unsupported-feature","abi"],"backgroundTag":"non-scalar-value-unsupported","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}