Skip to content

Index out of bounds on statics with non-JS types #1777

Closed
@unneon

Description

@unneon

Describe the Bug

Declaring and using a static with a type that is e.g. String or Option<_> compiles, but causes an index out of bounds error when running the wasm-bindgen CLI step in wasm-pack. Types that are handles to JavaScript values(JsValue, js_sys::Array, wasm-bindgen types generated from type declarations in extern "C" blocks) work fine.

Steps to Reproduce

Set up the following project, and run wasm-pack build.

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
    static EXTENSION_ROOT: String;
}

#[wasm_bindgen]
pub fn hello() -> String {
    EXTENSION_ROOT.clone()
}
[package]
name = "oopsie"
version = "0.1.0"
edition = "2018"

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

[dependencies]
wasm-bindgen = "0.2"

Expected Behavior

This should either create a static correctly and use *WasmAbi implicit conversions, or result in a non-panic error at some stage of compilation.

Actual Behavior

A panic in the build process occurs:

[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
    Finished release [optimized] target(s) in 0.01s
:-) [WARN]: origin crate has no README
[INFO]: Installing wasm-bindgen...
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', crates/cli-support/src/webidl/bindings.rs:209:36
stack backtrace:
   0: std::panicking::default_hook::{{closure}}
   1: std::panicking::default_hook
   2: std::panicking::rust_panic_with_hook
   3: std::panicking::continue_panic_fmt
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::panicking::panic_bounds_check
   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::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
Error: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit code: 101

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions