mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 11:12:48 +03:00
fix pushed but depends on pr #638
This commit is contained in:
parent
0698e550e3
commit
202f056531
@ -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),
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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(¶meter.variable.name) {
|
||||
|
@ -0,0 +1,2 @@
|
||||
[main]
|
||||
x: [i16; 1] = [0i16; 1];
|
@ -0,0 +1,3 @@
|
||||
function main(x: [i16; 2]){
|
||||
console.log("x: {}", x);
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user