E4042#
Compiler diagnostic name: invalid_stub_type.
Invalid stub type.
When defining an FFI function, each parameter and return type must be a valid stub type that can be represented natively by the selected backend.
For example, FixedArray[T] is not a valid stub type for the Wasm GC backend.
Erroneous example#
pub fn ffi(array : FixedArray[Int]) -> Unit = "mod" "ffi"
// ^~~~~~~~~~~~~~~
// Error: Invalid stub type.
Suggestion#
The way to pass non-native types through the FFI interface depends on both the backend of the MoonBit compiler and the runtime you are using. Use a native stub type directly, or pass a handle/index and manage the compound value on the host side.
pub fn ffi(value : Int) -> Unit = "mod" "ffi"