mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-24 02:31:44 +03:00
Merge pull request #251 from AleoHQ/fix/synthesis-error-stack-overflow
Fix/synthesis error stack overflow
This commit is contained in:
commit
c6ea9ad061
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
);
|
||||
|
||||
|
@ -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,
|
||||
);
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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,
|
||||
);
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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,
|
||||
|
3
compiler/tests/syntax/compare_mismatched_types.leo
Normal file
3
compiler/tests/syntax/compare_mismatched_types.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a = -5i8 > 342u32;
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user