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

bindgen: errors if interface and exported resource have same name #7775

Closed
jcbhmr opened this issue Jan 14, 2024 · 0 comments · Fixed by #7794
Closed

bindgen: errors if interface and exported resource have same name #7775

jcbhmr opened this issue Jan 14, 2024 · 0 comments · Fixed by #7794
Labels
bug Incorrect behavior in the current implementation that needs fixing

Comments

@jcbhmr
Copy link

jcbhmr commented Jan 14, 2024

Thanks for filing a bug report! Please fill out the TODOs below.

Note: if you want to report a security issue, please read our security policy!

Test Case

TODO: upload Wasm file here
no wasm. just rust.

Steps to Reproduce

  • TODO: first, ...
  • TODO: second, ...
  • Etc...
  • crate a new cargo project
  • add wasmtime with the component-model feature
  • use the below wit in the wit/ folder with bindgen!()
  • see error
package jcbhmr:hello-world-rust-wasm-component-lib;

interface my-box {
  resource my-box {
    constructor(value: u32);
    value: func() -> u32;
  }
  set-global: func(value: my-box);
  global-value: func() -> u32;
}

world example {
  export my-box;
}
use wasmtime::component::*;
use wasmtime::{Config, Engine, Store};

bindgen!();

Expected Results

it to either auto-rename it due to duplication or otherwise scope it so that this collision doesn't happen

Actual Results

image

jcbhmr@PIG-2016:~/Documents/rswasmtest$ cargo  build
   Compiling rswasmtest v0.1.0 (/home/jcbhmr/Documents/rswasmtest)
error[E0428]: the name `MyBox` is defined multiple times
 --> src/main.rs:4:1
  |
4 | bindgen!();
  | ^^^^^^^^^^ `MyBox` redefined here
  |
  = note: `MyBox` must be defined only once in the type namespace of this module
  = note: this error originates in the macro `bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
 --> src/main.rs:4:1
  |
4 | bindgen!();
  | ^^^^^^^^^^ impl for type defined outside of crate.
  |
  = note: define and implement a trait or new type instead
  = note: this error originates in the macro `bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0116, E0428.
For more information about an error, try `rustc --explain E0116`.
error: could not compile `rswasmtest` (bin "rswasmtest") due to 2 previous errors

Versions and Environment

Wasmtime version or commit: 16.0.0

Operating system: Windows 10 using WSL

Architecture: x86_64

Extra Info

Anything else you'd like to add?

@jcbhmr jcbhmr added the bug Incorrect behavior in the current implementation that needs fixing label Jan 14, 2024
alexcrichton added a commit to alexcrichton/wasmtime that referenced this issue Jan 18, 2024
This mirrors how traits for the host are all called `Host` and it avoids
name clashes with types that share the name of the interface they are in.

I've also added some simple debugging of macro-generated code to get
better error messages.

Closes bytecodealliance#7775
alexcrichton added a commit to alexcrichton/wasmtime that referenced this issue Jan 18, 2024
This mirrors how traits for the host are all called `Host` and it avoids
name clashes with types that share the name of the interface they are in.

I've also added some simple debugging of macro-generated code to get
better error messages.

Closes bytecodealliance#7775
alexcrichton added a commit to alexcrichton/wasmtime that referenced this issue Jan 18, 2024
This mirrors how traits for the host are all called `Host` and it avoids
name clashes with types that share the name of the interface they are in.

I've also added some simple debugging of macro-generated code to get
better error messages.

Closes bytecodealliance#7775
github-merge-queue bot pushed a commit that referenced this issue Jan 18, 2024
This mirrors how traits for the host are all called `Host` and it avoids
name clashes with types that share the name of the interface they are in.

I've also added some simple debugging of macro-generated code to get
better error messages.

Closes #7775
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant