Merge pull request #251 from AleoHQ/fix/synthesis-error-stack-overflow

Fix/synthesis error stack overflow
This commit is contained in:
Howard Wu 2020-08-19 01:25:34 -07:00 committed by GitHub
commit c6ea9ad061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 34 additions and 20 deletions

View File

@ -67,13 +67,19 @@ impl ExpressionError {
pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!(
"the gadget operation `{}` failed due to synthesis error `{}`",
"the gadget operation `{}` failed due to synthesis error `{:?}`",
operation, error,
);
Self::new_from_span(message, span)
}
pub fn cannot_evaluate(operation: String, span: Span) -> Self {
let message = format!("Mismatched types found for operation `{}`", operation);
Self::new_from_span(message, span)
}
pub fn conditional_boolean(actual: String, span: Span) -> Self {
let message = format!("if, else conditional must resolve to a boolean, found `{}`", actual);

View File

@ -44,7 +44,7 @@ impl AddressError {
pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!(
"the address operation `{}` failed due to the synthesis error `{}`",
"the address operation `{:?}` failed due to the synthesis error `{}`",
operation, error,
);

View File

@ -38,7 +38,7 @@ impl BooleanError {
pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!(
"the boolean operation `{}` failed due to the synthesis error `{}`",
"the boolean operation `{}` failed due to the synthesis error `{:?}`",
operation, error,
);

View File

@ -37,14 +37,14 @@ impl FieldError {
}
pub fn negate_operation(error: SynthesisError, span: Span) -> Self {
let message = format!("field negation failed due to synthesis error `{}`", error,);
let message = format!("field negation failed due to synthesis error `{:?}`", error,);
Self::new_from_span(message, span)
}
pub fn binary_operation(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!(
"the field binary operation `{}` failed due to synthesis error `{}`",
"the field binary operation `{}` failed due to synthesis error `{:?}`",
operation, error,
);
@ -70,7 +70,7 @@ impl FieldError {
}
pub fn synthesis_error(error: SynthesisError, span: Span) -> Self {
let message = format!("compilation failed due to field synthesis error `{}`", error);
let message = format!("compilation failed due to field synthesis error `{:?}`", error);
Self::new_from_span(message, span)
}

View File

@ -37,14 +37,14 @@ impl GroupError {
}
pub fn negate_operation(error: SynthesisError, span: Span) -> Self {
let message = format!("group negation failed due to the synthesis error `{}`", error,);
let message = format!("group negation failed due to the synthesis error `{:?}`", error,);
Self::new_from_span(message, span)
}
pub fn binary_operation(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!(
"the group binary operation `{}` failed due to the synthesis error `{}`",
"the group binary operation `{}` failed due to the synthesis error `{:?}`",
operation, error,
);
@ -64,7 +64,7 @@ impl GroupError {
}
pub fn synthesis_error(error: SynthesisError, span: Span) -> Self {
let message = format!("compilation failed due to group synthesis error `{}`", error);
let message = format!("compilation failed due to group synthesis error `{:?}`", error);
Self::new_from_span(message, span)
}

View File

@ -39,7 +39,7 @@ impl IntegerError {
pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!(
"the integer operation `{}` failed due to the synthesis error `{}`",
"the integer operation `{}` failed due to the synthesis error `{:?}`",
operation, error,
);

View File

@ -102,7 +102,7 @@ pub fn evaluate_eq<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
}
};
let boolean = constraint_result.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate equal"), e, span))?;
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("=="), span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -52,8 +52,7 @@ pub fn evaluate_ge<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
}
};
let boolean = constraint_result
.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate greater than or equal"), e, span))?;
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!(">="), span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -52,8 +52,7 @@ pub fn evaluate_gt<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
}
};
let boolean =
constraint_result.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate greater than"), e, span))?;
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!(">"), span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -52,8 +52,7 @@ pub fn evaluate_le<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
}
};
let boolean = constraint_result
.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate less than or equal"), e, span))?;
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("<="), span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -52,8 +52,7 @@ pub fn evaluate_lt<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
}
};
let boolean =
constraint_result.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate less than"), e, span))?;
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("<"), span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -189,7 +189,7 @@ macro_rules! test_int {
program.set_main_input(main_input);
expect_computation_error(program);
expect_compiler_error(program);
} else {
let c = match a.checked_div(b) {
Some(valid) => valid,

View File

@ -0,0 +1,3 @@
function main() {
let a = -5i8 > 342u32;
}

View File

@ -70,3 +70,12 @@ fn input_syntax_error() {
_ => panic!("input syntax error should be a ParserError"),
}
}
#[test]
fn test_compare_mismatched_types() {
let bytes = include_bytes!("compare_mismatched_types.leo");
let program = parse_program(bytes).unwrap();
// previously this bug caused a stack overflow
expect_compiler_error(program);
}