638: bug/563-array-input-wrong-dimensions r=collinc97 a=gluax

Closes #563. Fixes the array dimension builder when coming from the input file. Adds a test for it as well.

Co-authored-by: gluaxspeed <jonathan.t.pavlik@gmail.com>
This commit is contained in:
bors[bot] 2021-02-11 21:22:50 +00:00 committed by GitHub
commit d418b5330c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 1 deletions

View File

@ -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 {

View File

@ -0,0 +1,2 @@
[main]
x: [i16; (2, 2, 3)] = [0i16; (2, 2, 3)];

View File

@ -0,0 +1,9 @@
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);
console.assert(x[0][0][0] == y[0][0][0]);
console.assert(x[1][1][2] == y[1][1][2]);
}

View File

@ -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");