Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
22 changes: 21 additions & 1 deletion tests/all/component_model/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,27 @@ fn resource_any() -> Result<()> {
// reuse of `t` should fail, despite it pointing to a valid resource
assert_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"
);
}

Expand Down