A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
refactor: clarify error msg. for de-allocated `ResourceAny` (#12751)
Marco Neumann34caf6811ce0
diff --git a/crates/wasmtime/src/runtime/component/resources/host_tables.rs b/crates/wasmtime/src/runtime/component/resources/host_tables.rsindex 625035296b..8b83e1b58a 100644--- a/crates/wasmtime/src/runtime/component/resources/host_tables.rs+++ b/crates/wasmtime/src/runtime/component/resources/host_tables.rs@@ -177,7 +177,7 @@ impl<'a> HostResourceTables<'a> {// precise error, such as a lift operation.if let Some(actual) = actual {if actual.generation != idx.generation() {- bail!("host-owned resource is being used with the wrong type");+ bail!("host-owned resource was already de-allocated");}}diff --git a/tests/all/component_model/resources.rs b/tests/all/component_model/resources.rsindex 9b99e0d766..6f1fed7895 100644--- a/tests/all/component_model/resources.rs+++ b/tests/all/component_model/resources.rs@@ -187,7 +187,27 @@ fn resource_any() -> Result<()> {// reuse of `t` should fail, despite it pointing to a valid resourceassert_eq!(t_dtor.call(&mut store, (t,)).unwrap_err().to_string(),- "host-owned resource is being used with the wrong type"+ "host-owned resource was already de-allocated"+ );+ }++ {+ let mut store = Store::new(&engine, ());+ let i = linker.instantiate(&mut store, &c)?;+ let t_ctor = i.get_typed_func::<(u32,), (ResourceAny,)>(&mut store, "[constructor]t")?;+ let t_dtor = i.get_typed_func::<(ResourceAny,), ()>(&mut store, "drop-t")?;++ // `t0` is placed at host index 0+ let (t0,) = t_ctor.call(&mut store, (100,))?;+ t_dtor.call(&mut store, (t0,))?;++ // `t1` is also placed at host index 0 since `t0` was deallocated+ let (_t1,) = t_ctor.call(&mut store, (100,))?;++ // reuse of `t0` should fail, despite it pointing to a valid resource+ assert_eq!(+ t_dtor.call(&mut store, (t0,)).unwrap_err().to_string(),+ "host-owned resource was already de-allocated");}