diff --git a/ast/src/input/input_value.rs b/ast/src/input/input_value.rs index 5e08c2eb6a..5d6fba2a9e 100644 --- a/ast/src/input/input_value.rs +++ b/ast/src/input/input_value.rs @@ -177,7 +177,7 @@ impl InputValue { let mut elements = vec![]; // Build the elements of the array using the `vec!` macro - for (i, dimension) in initializer_dimensions.into_iter().enumerate() { + for (i, dimension) in initializer_dimensions.into_iter().rev().enumerate() { if i == 0 { elements = vec![value.clone(); dimension]; } else { diff --git a/compiler/tests/input_files/program_input/input/main_multi_dimension_array.in b/compiler/tests/input_files/program_input/input/main_multi_dimension_array.in new file mode 100644 index 0000000000..e62ec2f232 --- /dev/null +++ b/compiler/tests/input_files/program_input/input/main_multi_dimension_array.in @@ -0,0 +1,2 @@ +[main] +x: [i16; (2, 2, 3)] = [0i16; (2, 2, 3)]; \ No newline at end of file diff --git a/compiler/tests/input_files/program_input/main_multi_dimension_array.leo b/compiler/tests/input_files/program_input/main_multi_dimension_array.leo new file mode 100644 index 0000000000..582cf45a11 --- /dev/null +++ b/compiler/tests/input_files/program_input/main_multi_dimension_array.leo @@ -0,0 +1,6 @@ +function main(x: [i16; (2, 2, 3)]){ + console.log("x: {}", x); + + let y: [i16; (2, 2, 3)] = [0i16; (2, 2, 3)]; + console.log("y: {}", y); +} \ No newline at end of file diff --git a/compiler/tests/input_files/program_input/mod.rs b/compiler/tests/input_files/program_input/mod.rs index b0731d0f4b..6c5d2bbb99 100644 --- a/compiler/tests/input_files/program_input/mod.rs +++ b/compiler/tests/input_files/program_input/mod.rs @@ -44,6 +44,16 @@ fn test_input_array_fail() { assert_satisfied(program); } +#[test] +fn test_input_multi_dimension_array() { + let program_string = include_str!("main_multi_dimension_array.leo"); + let input_string = include_str!("input/main_multi_dimension_array.in"); + + let program = parse_program_with_input(program_string, input_string).unwrap(); + + assert_satisfied(program); +} + #[test] fn test_input_fail_name() { let program_string = include_str!("main.leo");