From b3c140d5bbae66648e4206fbd3497fed175b1f9f Mon Sep 17 00:00:00 2001 From: collin Date: Mon, 26 Oct 2020 13:14:36 -0700 Subject: [PATCH] fix array function input bug --- .../tests/core/packages/unstable/blake2s/mod.rs | 5 ++--- compiler/tests/function/array_input.leo | 6 ++++++ compiler/tests/function/mod.rs | 8 ++++++++ dynamic-check/src/dynamic_check.rs | 2 -- static-check/src/types/type_.rs | 15 ++++++++++++--- 5 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 compiler/tests/function/array_input.leo diff --git a/compiler/tests/core/packages/unstable/blake2s/mod.rs b/compiler/tests/core/packages/unstable/blake2s/mod.rs index 3cf5e54993..83ec7d15a1 100644 --- a/compiler/tests/core/packages/unstable/blake2s/mod.rs +++ b/compiler/tests/core/packages/unstable/blake2s/mod.rs @@ -16,7 +16,6 @@ use crate::{ assert_satisfied, - expect_compiler_error, expect_dynamic_check_error, generate_main_input, get_output, @@ -42,9 +41,9 @@ fn test_arguments_length_fail() { #[test] fn test_arguments_type_fail() { let program_bytes = include_bytes!("arguments_type_fail.leo"); - let program = parse_program(program_bytes).unwrap(); + let error = parse_program(program_bytes).err().unwrap(); - expect_compiler_error(program); + expect_dynamic_check_error(error); } #[test] diff --git a/compiler/tests/function/array_input.leo b/compiler/tests/function/array_input.leo new file mode 100644 index 0000000000..a70483cae7 --- /dev/null +++ b/compiler/tests/function/array_input.leo @@ -0,0 +1,6 @@ +function foo(a: [u8; 1]) {} + +function main() { + let a: [u16; 1] = [1; 1]; + foo(a); +} \ No newline at end of file diff --git a/compiler/tests/function/mod.rs b/compiler/tests/function/mod.rs index 69e9d1b980..7b9cfdd750 100644 --- a/compiler/tests/function/mod.rs +++ b/compiler/tests/function/mod.rs @@ -133,6 +133,14 @@ fn test_value_unchanged() { assert_satisfied(program); } +#[test] +fn test_array_input() { + let bytes = include_bytes!("array_input.leo"); + let error = parse_program(bytes).err().unwrap(); + + expect_dynamic_check_error(error) +} + // Test return multidimensional arrays #[test] diff --git a/dynamic-check/src/dynamic_check.rs b/dynamic-check/src/dynamic_check.rs index 82a9cd191c..2ebdb0b551 100644 --- a/dynamic-check/src/dynamic_check.rs +++ b/dynamic-check/src/dynamic_check.rs @@ -1050,8 +1050,6 @@ impl Frame { .ok_or_else(|| FrameError::undefined_circuit(identifier))? }; - println!("circuit_type: {:?}", circuit_type); - // Check the length of the circuit members. if circuit_type.variables.len() != members.len() { return Err(FrameError::num_variables( diff --git a/static-check/src/types/type_.rs b/static-check/src/types/type_.rs index 69c7a346da..11fb31e280 100644 --- a/static-check/src/types/type_.rs +++ b/static-check/src/types/type_.rs @@ -238,10 +238,19 @@ impl Type { /// Replaces self with the given type if self is equal to the given `TypeVariable`. /// pub fn substitute(&mut self, variable: &TypeVariable, type_: &Type) { - if let Type::TypeVariable(self_variable) = self { - if self_variable == variable { - *self = type_.to_owned() + match self { + Type::TypeVariable(self_variable) => { + if self_variable == variable { + *self = type_.to_owned() + } } + Type::Array(self_type, _) => { + self_type.substitute(variable, type_); + } + Type::Tuple(types) => types + .iter_mut() + .for_each(|tuple_type| tuple_type.substitute(variable, type_)), + _ => {} } } }