A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Print fixed-length lists with WAVE (#14068)
subotacff1cab3437cf
diff --git a/crates/wasmtime/src/runtime/wave/component.rs b/crates/wasmtime/src/runtime/wave/component.rsindex 6b795305ed..7c7b50013b 100644--- a/crates/wasmtime/src/runtime/wave/component.rs+++ b/crates/wasmtime/src/runtime/wave/component.rs@@ -261,7 +261,10 @@ impl WasmValue for component::Val {unwrap_val!(self, Self::String, "string").into()}fn unwrap_list(&self) -> Box<dyn Iterator<Item = Cow<'_, Self>> + '_> {- let list = unwrap_val!(self, Self::List, "list");+ let list = match self {+ Self::List(list) | Self::FixedLengthList(list) => list,+ _ => panic!("called unwrap_list on non-list value"),+ };Box::new(list.iter().map(cow))}fn unwrap_record(&self) -> Box<dyn Iterator<Item = (Cow<'_, str>, Cow<'_, Self>)> + '_> {diff --git a/tests/all/component_model/fixed_length_list.rs b/tests/all/component_model/fixed_length_list.rsindex 84dd928b11..8542673948 100644--- a/tests/all/component_model/fixed_length_list.rs+++ b/tests/all/component_model/fixed_length_list.rs@@ -298,3 +298,30 @@ fn fixed_length_list_length_mismatch_rejected() -> Result<()> {assert_eq!(out, 0x1234_5678);Ok(())}++#[test]+fn fixed_length_list_wave() -> Result<()> {+ let wat = r#"+(component+ (core module $m+ (func (export "f") (result i32) (i32.const 7))+ )+ (core instance $i (instantiate $m))+ (func (export "f") (result (list u32 1)) (canon lift (core func $i "f")))+)+"#;++ let mut config = Config::new();+ config.wasm_component_model_fixed_length_lists(true);+ let engine = Engine::new(&config)?;+ let component = Component::new(&engine, wat)?;+ let mut store = Store::new(&engine, ());+ let instance = Linker::new(&engine).instantiate(&mut store, &component)?;+ let func = instance.get_func(&mut store, "f").unwrap();+ let mut results = [Val::Bool(false)];++ func.call(&mut store, &[], &mut results)?;+ assert_eq!(results[0].to_wave()?, "[7]");++ Ok(())+}