Skip to content

Commit

Permalink
Fix the exports key for packages-with-versions (#677)
Browse files Browse the repository at this point in the history
Previously one location looking up `exports` would account for
the version and another wouldn't which caused the `ERROR` case to leak
through by accident. These are now kept in sync to ensure that the right
errors get surfaced.
  • Loading branch information
alexcrichton authored Sep 26, 2023
1 parent f1e8c06 commit 08de0ea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
18 changes: 4 additions & 14 deletions crates/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,24 +296,14 @@ impl WorldGenerator for RustWasm {
id: InterfaceId,
_files: &mut Files,
) -> Result<()> {
let (pkg, inner_name) = match name {
WorldKey::Name(name) => (None, name),
let inner_name = match name {
WorldKey::Name(name) => name,
WorldKey::Interface(id) => {
let interface = &resolve.interfaces[*id];
(
Some(&resolve.packages[interface.package.unwrap()].name),
interface.name.as_ref().unwrap(),
)
interface.name.as_ref().unwrap()
}
};
let path = format!(
"{}{inner_name}",
if let Some(pkg) = pkg {
format!("{}:{}/", pkg.namespace, pkg.name)
} else {
String::new()
}
);
let path = resolve.id_of(id).unwrap_or(inner_name.to_string());
let mut gen = self.interface(Identifier::Interface(id, name), None, resolve, false);
let (snake, pkg) = gen.start_append_submodule(name);
gen.types(id);
Expand Down
30 changes: 29 additions & 1 deletion crates/rust/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ mod symbol_does_not_conflict {
bar: func() -> string
}
world foo {
export foo1
export foo2
Expand Down Expand Up @@ -272,3 +271,32 @@ mod owned_resource_deref_mut {
}
}
}

mod package_with_versions {
wit_bindgen::generate!({
inline: "
package my:[email protected]
interface foo {
resource bar {
constructor()
}
}
world baz {
export foo
}
",
exports: {
"my:inline/[email protected]/bar": Resource
}
});

pub struct Resource;

impl exports::my::inline::foo::GuestBar for Resource {
fn new() -> Self {
loop {}
}
}
}

0 comments on commit 08de0ea

Please sign in to comment.