fix struct field validation. make if conditional parenthesis optional

This commit is contained in:
collin 2020-05-11 13:18:40 -07:00
parent daf68d7aee
commit 75a47c55dd
4 changed files with 14 additions and 2 deletions

View File

@ -360,6 +360,9 @@ impl<F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgram<F, CS> {
member.expression,
)?;
// Check member types
member_value.expect_type(&field._type)?;
resolved_members.push(ConstrainedStructMember(member.variable, member_value))
}

View File

@ -1,4 +1,4 @@
use crate::errors::{BooleanError, FieldElementError, FunctionError, IntegerError};
use crate::errors::{BooleanError, FieldElementError, FunctionError, IntegerError, ValueError};
#[derive(Debug, Error)]
pub enum ExpressionError {
@ -13,6 +13,9 @@ pub enum ExpressionError {
#[error("{}", _0)]
IncompatibleTypes(String),
#[error("{}", _0)]
ValueError(ValueError),
#[error("{}", _0)]
IntegerError(IntegerError),
@ -81,6 +84,12 @@ impl From<std::io::Error> for ExpressionError {
}
}
impl From<ValueError> for ExpressionError {
fn from(error: ValueError) -> Self {
ExpressionError::ValueError(error)
}
}
impl From<IntegerError> for ExpressionError {
fn from(error: IntegerError) -> Self {
ExpressionError::IntegerError(error)

View File

@ -174,7 +174,7 @@ statement_return = { "return" ~ expression_tuple }
statement_definition = { "let" ~ variable ~ (":" ~ _type)? ~ "=" ~ expression }
statement_assign = { assignee ~ operation_assign ~ expression }
statement_multiple_assignment = { "let" ~ "(" ~ optionally_typed_variable_tuple ~ ")" ~ "=" ~ variable ~ "(" ~ expression_tuple ~ ")" }
statement_conditional = {"if" ~ "(" ~ expression ~ ")" ~ "{" ~ NEWLINE* ~ statement+ ~ "}" ~ ("else" ~ conditional_nested_or_end)?}
statement_conditional = {"if" ~ (expression | "(" ~ expression ~ ")") ~ "{" ~ NEWLINE* ~ statement+ ~ "}" ~ ("else" ~ conditional_nested_or_end)?}
statement_for = { "for" ~ variable ~ "in" ~ expression ~ ".." ~ expression ~ "{" ~ NEWLINE* ~ statement+ ~ "}"}
statement_assert = {
assert_eq

0
stdlib/crh/pedersen.leo Normal file
View File