A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Adjust `ValType::ty` for externrefs (#15170)
Alex Crichton07f543121915
diff --git a/crates/wasmtime/src/runtime/values.rs b/crates/wasmtime/src/runtime/values.rsindex 6839863a5c..a142ab2a87 100644--- a/crates/wasmtime/src/runtime/values.rs+++ b/crates/wasmtime/src/runtime/values.rs@@ -168,7 +168,10 @@ impl Val {Val::F32(_) => ValType::F32,Val::F64(_) => ValType::F64,Val::V128(_) => ValType::V128,- Val::ExternRef(Some(_)) => ValType::EXTERNREF,+ Val::ExternRef(Some(e)) => {+ e.try_gc_ref(store)?;+ ValType::Ref(RefType::new(false, HeapType::Extern))+ }Val::ExternRef(None) => ValType::NULLEXTERNREF,Val::FuncRef(None) => ValType::NULLFUNCREF,Val::FuncRef(Some(f)) => ValType::Ref(RefType::new(diff --git a/tests/all/gc.rs b/tests/all/gc.rsindex db3424b982..2d045f5094 100644--- a/tests/all/gc.rs+++ b/tests/all/gc.rs@@ -2568,6 +2568,24 @@ fn anyref_ty_extern_converted() -> Result<()> {Ok(())}+#[test]+fn externref_val_ty() -> Result<()> {+ let mut store = gc_store()?;+ let live = ExternRef::new(&mut store, 1u32)?;+ let ty = Val::ExternRef(Some(live)).ty(&store)?;+ assert!(ValType::eq(+ &ty,+ &ValType::Ref(RefType::new(false, HeapType::Extern))+ ));++ let unrooted = {+ let mut scope = RootScope::new(&mut store);+ ExternRef::new(&mut scope, 2u32)?+ };+ assert!(Val::ExternRef(Some(unrooted)).ty(&store).is_err());+ Ok(())+}+#[test]fn anyref_to_raw_struct() -> Result<()> {let mut store = gc_store()?;