diff --git a/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs b/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs index 3056fb5973d..61dfa096fce 100644 --- a/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs +++ b/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs @@ -121,16 +121,18 @@ impl FunctionBuilder { databus.index += 1; } Type::Array(typ, len) => { - assert!(typ.len() == 1, "unsupported composite type"); databus.map.insert(value, databus.index); for i in 0..len { - // load each element of the array - let index = self - .current_function - .dfg - .make_constant(FieldElement::from(i as i128), Type::length_type()); - let element = self.insert_array_get(value, index, typ[0].clone()); - self.add_to_data_bus(element, databus); + for (subitem_index, subitem_typ) in typ.iter().enumerate() { + let index = i * typ.len() + subitem_index; + // load each element of the array + let index = self + .current_function + .dfg + .make_constant(FieldElement::from(index as i128), Type::length_type()); + let element = self.insert_array_get(value, index, subitem_typ.clone()); + self.add_to_data_bus(element, databus); + } } } Type::Reference(_) => { diff --git a/test_programs/execution_success/databus_composite_calldata/Nargo.toml b/test_programs/execution_success/databus_composite_calldata/Nargo.toml new file mode 100644 index 00000000000..38c916e5d97 --- /dev/null +++ b/test_programs/execution_success/databus_composite_calldata/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "databus_composite_calldata" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/databus_composite_calldata/Prover.toml b/test_programs/execution_success/databus_composite_calldata/Prover.toml new file mode 100644 index 00000000000..ff173cc70cd --- /dev/null +++ b/test_programs/execution_success/databus_composite_calldata/Prover.toml @@ -0,0 +1,9 @@ +zero = "0" +one = "1" +[[foos]] +x = "27" +y = "40" + +[[foos]] +x = "28" +y = "42" diff --git a/test_programs/execution_success/databus_composite_calldata/src/main.nr b/test_programs/execution_success/databus_composite_calldata/src/main.nr new file mode 100644 index 00000000000..c4da253cbce --- /dev/null +++ b/test_programs/execution_success/databus_composite_calldata/src/main.nr @@ -0,0 +1,11 @@ +struct Foo { + x: u32, + y: u32, +} + +fn main(foos: call_data(0) [Foo; 2], zero: u32, one: u32) -> return_data u32 { + assert_eq(foos[zero].x + 1, foos[one].x); + assert_eq(foos[zero].y + 2, foos[one].y); + foos[zero].x + foos[one].y +} +