wasm-bindgen icon indicating copy to clipboard operation
wasm-bindgen copied to clipboard

enum with method references non-existent free/destructor function

Open kev1n-peters opened this issue 3 years ago • 1 comments

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').

kev1n-peters avatar Feb 08 '22 02:02 kev1n-peters

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

petrstudynka avatar Apr 07 '22 14:04 petrstudynka