mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-28 01:01:53 +03:00
fix refactored array initializer tests wip 2
This commit is contained in:
parent
aa17355a72
commit
34b425ffe5
@ -153,18 +153,37 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
None => return Err(ExpressionError::unexpected_array(type_.to_string(), span)),
|
||||
};
|
||||
|
||||
// Update the actual array dimensions.
|
||||
let _first_dimension = actual_dimensions.remove_first();
|
||||
|
||||
// Update the expected type to a new array type with the first dimension removed.
|
||||
let expected_expression_type = Some(inner_array_type(*type_, expected_dimensions));
|
||||
println!("expected type {:?}", expected_expression_type);
|
||||
|
||||
// Get the value of the array element.
|
||||
let element_value = self.enforce_expression(
|
||||
cs,
|
||||
file_scope,
|
||||
function_scope,
|
||||
expected_expression_type,
|
||||
element_expression,
|
||||
)?;
|
||||
// If the expression has more dimensions.
|
||||
let element_value = match actual_dimensions.first() {
|
||||
Some(_dimension) => {
|
||||
// Get the value of the array element as an initializer.
|
||||
self.enforce_array_initializer(
|
||||
cs,
|
||||
file_scope,
|
||||
function_scope,
|
||||
expected_expression_type,
|
||||
element_expression,
|
||||
actual_dimensions.clone(),
|
||||
span.clone(),
|
||||
)?
|
||||
}
|
||||
None => {
|
||||
// Get the value of the array element as an expression.
|
||||
self.enforce_expression(
|
||||
cs,
|
||||
file_scope,
|
||||
function_scope,
|
||||
expected_expression_type,
|
||||
element_expression,
|
||||
)?
|
||||
}
|
||||
};
|
||||
|
||||
// Allocate the array of values.
|
||||
let array_values = vec![element_value; dimension];
|
||||
|
@ -44,7 +44,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
expected_type: Option<Type>,
|
||||
expression: Expression,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
println!("expr {}", expression);
|
||||
match expression {
|
||||
// Variables
|
||||
Expression::Identifier(unresolved_variable) => {
|
||||
|
@ -17,7 +17,6 @@
|
||||
use crate::{
|
||||
assert_satisfied,
|
||||
expect_compiler_error,
|
||||
expect_type_inference_error,
|
||||
get_output,
|
||||
parse_program,
|
||||
parse_program_with_input,
|
||||
@ -191,9 +190,9 @@ fn test_nested_3x2_value() {
|
||||
#[test]
|
||||
fn test_nested_3x2_value_fail() {
|
||||
let program_bytes = include_bytes!("nested_3x2_value_fail.leo");
|
||||
let error = parse_program(program_bytes).err().unwrap();
|
||||
let program = parse_program(program_bytes).unwrap();
|
||||
|
||||
expect_type_inference_error(error);
|
||||
let _err = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -207,9 +206,9 @@ fn test_tuple_3x2_value() {
|
||||
#[test]
|
||||
fn test_tuple_3x2_value_fail() {
|
||||
let program_bytes = include_bytes!("tuple_3x2_value_fail.leo");
|
||||
let error = parse_program(program_bytes).err().unwrap();
|
||||
let program = parse_program(program_bytes).unwrap();
|
||||
|
||||
expect_type_inference_error(error);
|
||||
let _err = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -251,9 +250,9 @@ fn test_type_nested_value_nested_3x2() {
|
||||
#[test]
|
||||
fn test_type_nested_value_nested_3x2_fail() {
|
||||
let program_bytes = include_bytes!("type_nested_value_nested_3x2_fail.leo");
|
||||
let error = parse_program(program_bytes).err().unwrap();
|
||||
let program = parse_program(program_bytes).unwrap();
|
||||
|
||||
expect_type_inference_error(error);
|
||||
let _err = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -267,9 +266,9 @@ fn test_type_nested_value_nested_4x3x2() {
|
||||
#[test]
|
||||
fn test_type_nested_value_nested_4x3x2_fail() {
|
||||
let program_bytes = include_bytes!("type_nested_value_nested_4x3x2_fail.leo");
|
||||
let error = parse_program(program_bytes).err().unwrap();
|
||||
let program = parse_program(program_bytes).unwrap();
|
||||
|
||||
expect_type_inference_error(error);
|
||||
let _err = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -283,9 +282,9 @@ fn test_type_nested_value_tuple_3x2() {
|
||||
#[test]
|
||||
fn test_type_nested_value_tuple_3x2_fail() {
|
||||
let program_bytes = include_bytes!("type_nested_value_tuple_3x2_fail.leo");
|
||||
let error = parse_program(program_bytes).err().unwrap();
|
||||
let program = parse_program(program_bytes).unwrap();
|
||||
|
||||
expect_type_inference_error(error);
|
||||
let _err = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -299,9 +298,9 @@ fn test_type_nested_value_tuple_4x3x2() {
|
||||
#[test]
|
||||
fn test_type_nested_value_tuple_4x3x2_fail() {
|
||||
let program_bytes = include_bytes!("type_nested_value_tuple_4x3x2_fail.leo");
|
||||
let error = parse_program(program_bytes).err().unwrap();
|
||||
let program = parse_program(program_bytes).unwrap();
|
||||
|
||||
expect_type_inference_error(error);
|
||||
let _err = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -315,9 +314,9 @@ fn test_type_tuple_value_nested_3x2() {
|
||||
#[test]
|
||||
fn test_type_tuple_value_nested_3x2_fail() {
|
||||
let program_bytes = include_bytes!("type_tuple_value_nested_3x2_fail.leo");
|
||||
let error = parse_program(program_bytes).err().unwrap();
|
||||
let program = parse_program(program_bytes).unwrap();
|
||||
|
||||
expect_type_inference_error(error);
|
||||
let _err = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -331,9 +330,9 @@ fn test_type_tuple_value_nested_4x3x2() {
|
||||
#[test]
|
||||
fn test_type_tuple_value_nested_4x3x2_fail() {
|
||||
let program_bytes = include_bytes!("type_tuple_value_nested_4x3x2_fail.leo");
|
||||
let error = parse_program(program_bytes).err().unwrap();
|
||||
let program = parse_program(program_bytes).unwrap();
|
||||
|
||||
expect_type_inference_error(error);
|
||||
let _err = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -347,9 +346,9 @@ fn test_type_tuple_value_tuple_3x2() {
|
||||
#[test]
|
||||
fn test_type_tuple_value_tuple_3x2_fail() {
|
||||
let program_bytes = include_bytes!("type_tuple_value_tuple_3x2_fail.leo");
|
||||
let error = parse_program(program_bytes).err().unwrap();
|
||||
let program = parse_program(program_bytes).unwrap();
|
||||
|
||||
expect_type_inference_error(error);
|
||||
let _err = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -363,9 +362,9 @@ fn test_type_tuple_value_tuple_4x3x2() {
|
||||
#[test]
|
||||
fn test_type_tuple_value_tuple_4x3x2_fail() {
|
||||
let program_bytes = include_bytes!("type_tuple_value_tuple_4x3x2_fail.leo");
|
||||
let error = parse_program(program_bytes).err().unwrap();
|
||||
let program = parse_program(program_bytes).unwrap();
|
||||
|
||||
expect_type_inference_error(error);
|
||||
let _err = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
// Tests for nested multi-dimensional arrays as input to the program
|
||||
|
Loading…
Reference in New Issue
Block a user