Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple identical extern functions with different types causes panic in wasm_bindgen #1866

Open
hansihe opened this issue Nov 20, 2019 · 1 comment
Labels

Comments

@hansihe
Copy link

hansihe commented Nov 20, 2019

Steps to Reproduce

Run wasm-pack test --node on the following crate:

Cargo.toml:

[package]
name = "reprod"
version = "0.0.0"
authors = []
edition = "2018"

[lib]
crate-type = ["cdylib"]

[dependencies]
js-sys = "0.3"
wasm-bindgen = "0.2"

[dev-dependencies]
wasm-bindgen-test = "0.2"

lib.rs:

mod a {
    use wasm_bindgen::prelude::*;

    #[wasm_bindgen]
    extern "C" {
        #[wasm_bindgen(js_namespace = console)]
        fn log(s: &str);
    }

}

mod b {

    use wasm_bindgen::prelude::*;
    use wasm_bindgen_test::*;
    use js_sys::{JsString};

    #[wasm_bindgen]
    extern "C" {
        #[wasm_bindgen(js_namespace = console)]
        fn log(s: &JsString);
    }

    #[wasm_bindgen_test]
    fn aa() {
        let string = JsString::from_char_code(&[]);
        log(&string);
    }

}

If applicable, add a link to a test case (as a zip file or link to a repository we can clone).

Expected Behavior

Either:

  1. An error message describing what I'm doing wrong
  2. No panic

Actual Behavior

hansihe@hansihe-XPS-13-9370:~/proj/rust/bindgen_run_reprod$ wasm-pack test --node
[INFO]: Checking for the Wasm target...
   Compiling screeps_anathema v0.0.0 (/home/hansihe/proj/rust/bindgen_run_reprod)
    Finished dev [unoptimized + debuginfo] target(s) in 0.78s
[INFO]: Installing wasm-bindgen...
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running target/wasm32-unknown-unknown/debug/deps/screeps_anathema-c294c97529e4fd68.wasm
thread 'main' panicked at 'assertion failed: iter.next().is_none()', crates/cli-support/src/webidl/bindings.rs:227:5
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic
   7: wasm_bindgen_cli_support::webidl::bindings::assert_signature_match
   8: wasm_bindgen_cli_support::webidl::bindings::register_import
   9: wasm_bindgen_cli_support::webidl::Context::program
  10: wasm_bindgen_cli_support::webidl::process
  11: wasm_bindgen_cli_support::Bindgen::generate_output
  12: wasm_bindgen_cli_support::Bindgen::generate
  13: wasm_bindgen_test_runner::main
  14: std::rt::lang_start::{{closure}}
  15: std::panicking::try::do_call
  16: __rust_maybe_catch_panic
  17: std::rt::lang_start_internal
  18: main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: test failed, to rerun pass '--lib'         
Error: Running Wasm tests with wasm-bindgen-test failed
Caused by: failed to execute `cargo test`: exited with exit code: 101
hansihe@hansihe-XPS-13-9370:~/proj/rust/bindgen_run_reprod$ 
@hansihe hansihe added the bug label Nov 20, 2019
@alexcrichton
Copy link
Contributor

Sorry for the delay in commenting on this, but thanks for the report!

I think this is a bug in the CLI where it's a panic, instead a first-class error should likely be reported. I unfortunately won't have time to get around to this for some time, but it's good to have this logged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants