List exports of an instance in linking error (#3456)

When there is a linking error caused by an undefined instance, list all
the instances exports in the error message. This will clarify errors for
undefined two-level imports that get desugared to one-level instance
imports under the module-linking proposal.
This commit is contained in:
Adam Bratschi-Kaye
2021-10-20 23:31:53 +02:00
committed by GitHub
parent fb585fde40
commit afd10646c9
2 changed files with 45 additions and 22 deletions

View File

@@ -23,6 +23,34 @@ fn link_undefined() -> Result<()> {
Ok(())
}
#[test]
fn undefined_error_message_with_linking() {
let mut config = Config::new();
config.wasm_module_linking(true);
let engine = Engine::new(&config).unwrap();
let module = Module::new(
&engine,
r#"
(module
(import "foo" "bar" (func))
)
"#,
)
.unwrap();
let linker = Linker::new(&engine);
let mut store = Store::new(&engine, ());
assert!(linker
.instantiate(&mut store, &module)
.unwrap_err()
.to_string()
.contains("foo"));
assert!(linker
.instantiate(&mut store, &module)
.unwrap_err()
.to_string()
.contains("bar"));
}
#[test]
fn link_twice_bad() -> Result<()> {
let mut store = Store::<()>::default();