wasm-bindgen
wasm-bindgen copied to clipboard
enum with method references non-existent free/destructor function
Describe the Bug
The JavaScript generated for an enum with a method references a non-existent function.
Steps to Reproduce
// lib.rs
use wasm_bindgen::prelude::*;
pub enum Foo {}
#[wasm_bindgen]
impl Foo {
pub fn foo() {}
}
wasm-pack build
// foo_bg.js
import * as wasm from './foo_bg.wasm';
export class Foo {
__destroy_into_raw() {
const ptr = this.ptr;
this.ptr = 0;
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_foo_free(ptr); // <-- This function does not exist
}
static foo() {
wasm.foo_foo();
}
}
Attempted import error: '__wbg_foo_free' is not exported from './foo_bg.wasm' (imported as 'wasm').
You are missing annotation #[wasm_bindgen] above Foo.
However this still does not compile if impl Foo block has any method:
error: cannot shadow already defined class Foo