fix pushed but depends on pr #638

This commit is contained in:
gluaxspeed 2021-02-10 11:57:10 -05:00
parent 0698e550e3
commit 202f056531
7 changed files with 33 additions and 2 deletions

View File

@ -25,7 +25,7 @@ use pest::Span;
use std::fmt;
#[derive(Clone, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum InputValue {
Address(String),
Boolean(bool),

View File

@ -93,6 +93,15 @@ impl FunctionError {
Self::new_from_span(message, span)
}
pub fn invalid_input_array_dimensions(expected: usize, actual: usize, span: Span) -> Self {
let message = format!(
"Input array dimensions mismatch expected {}, found array dimensions {}",
expected, actual
);
Self::new_from_span(message, span)
}
pub fn invalid_tuple(actual: String, span: Span) -> Self {
let message = format!("Expected function input tuple, found `{}`", actual);

View File

@ -41,6 +41,14 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
match input_value {
Some(InputValue::Array(arr)) => {
if array_len != arr.len() {
return Err(FunctionError::invalid_input_array_dimensions(
arr.len(),
array_len,
span.clone(),
));
}
// Allocate each value in the current row
for (i, value) in arr.into_iter().enumerate() {
let value_name = format!("{}_{}", &name, &i.to_string());

View File

@ -37,7 +37,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
let mut members = Vec::with_capacity(section.len());
// Allocate each section definition as a circuit member value
for (parameter, option) in section.into_iter() {
let section_members = expected_type.members.borrow();
let expected_type = match section_members.get(&parameter.variable.name) {

View File

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

View File

@ -0,0 +1,3 @@
function main(x: [i16; 2]){
console.log("x: {}", x);
}

View File

@ -73,3 +73,13 @@ fn test_input_multiple() {
assert_satisfied(program);
}
#[test]
fn test_input_array_dimensions_mismatch() {
let program_string = include_str!("main_array_fail.leo");
let input_string = include_str!("input/main_array_fail.in");
let program = parse_program_with_input(program_string, input_string).unwrap();
assert_satisfied(program);
}