fix array function input bug

This commit is contained in:
collin 2020-10-26 13:14:36 -07:00
parent 9bae1037f7
commit b3c140d5bb
5 changed files with 28 additions and 8 deletions

View File

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

View File

@ -0,0 +1,6 @@
function foo(a: [u8; 1]) {}
function main() {
let a: [u16; 1] = [1; 1];
foo(a);
}

View File

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

View File

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

View File

@ -238,11 +238,20 @@ 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 {
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_)),
_ => {}
}
}
}