diff --git a/compiler/src/errors/expression.rs b/compiler/src/errors/expression.rs index d388318bd5..d28382ee33 100644 --- a/compiler/src/errors/expression.rs +++ b/compiler/src/errors/expression.rs @@ -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); diff --git a/compiler/src/errors/value/address.rs b/compiler/src/errors/value/address.rs index d2239814ca..29eeec73c2 100644 --- a/compiler/src/errors/value/address.rs +++ b/compiler/src/errors/value/address.rs @@ -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, ); diff --git a/compiler/src/errors/value/boolean.rs b/compiler/src/errors/value/boolean.rs index 639cfb0743..dee94702aa 100644 --- a/compiler/src/errors/value/boolean.rs +++ b/compiler/src/errors/value/boolean.rs @@ -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, ); diff --git a/compiler/src/errors/value/field.rs b/compiler/src/errors/value/field.rs index 662da36302..47d06a0548 100644 --- a/compiler/src/errors/value/field.rs +++ b/compiler/src/errors/value/field.rs @@ -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) } diff --git a/compiler/src/errors/value/group.rs b/compiler/src/errors/value/group.rs index c7b84b5f56..ecd9d6257b 100644 --- a/compiler/src/errors/value/group.rs +++ b/compiler/src/errors/value/group.rs @@ -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) } diff --git a/compiler/src/errors/value/integer.rs b/compiler/src/errors/value/integer.rs index f1ccba5aeb..6ddd228dfd 100644 --- a/compiler/src/errors/value/integer.rs +++ b/compiler/src/errors/value/integer.rs @@ -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, ); diff --git a/compiler/src/expression/relational/eq.rs b/compiler/src/expression/relational/eq.rs index 71a4b4d099..706db5bb02 100644 --- a/compiler/src/expression/relational/eq.rs +++ b/compiler/src/expression/relational/eq.rs @@ -102,7 +102,7 @@ pub fn evaluate_eq, 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)) } diff --git a/compiler/src/expression/relational/ge.rs b/compiler/src/expression/relational/ge.rs index 0589b82e7f..fd9dc43e04 100644 --- a/compiler/src/expression/relational/ge.rs +++ b/compiler/src/expression/relational/ge.rs @@ -52,8 +52,7 @@ pub fn evaluate_ge, 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)) } diff --git a/compiler/src/expression/relational/gt.rs b/compiler/src/expression/relational/gt.rs index 5b26b1acc1..57228d39e2 100644 --- a/compiler/src/expression/relational/gt.rs +++ b/compiler/src/expression/relational/gt.rs @@ -52,8 +52,7 @@ pub fn evaluate_gt, 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)) } diff --git a/compiler/src/expression/relational/le.rs b/compiler/src/expression/relational/le.rs index a07051d9ed..5eca4c7656 100644 --- a/compiler/src/expression/relational/le.rs +++ b/compiler/src/expression/relational/le.rs @@ -52,8 +52,7 @@ pub fn evaluate_le, 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)) } diff --git a/compiler/src/expression/relational/lt.rs b/compiler/src/expression/relational/lt.rs index 611d9f3661..41b954117e 100644 --- a/compiler/src/expression/relational/lt.rs +++ b/compiler/src/expression/relational/lt.rs @@ -52,8 +52,7 @@ pub fn evaluate_lt, 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)) } diff --git a/compiler/tests/integers/int_macro.rs b/compiler/tests/integers/int_macro.rs index a074f5c420..cdcd3e7f3d 100644 --- a/compiler/tests/integers/int_macro.rs +++ b/compiler/tests/integers/int_macro.rs @@ -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, diff --git a/compiler/tests/syntax/compare_mismatched_types.leo b/compiler/tests/syntax/compare_mismatched_types.leo new file mode 100644 index 0000000000..8cf6327cb3 --- /dev/null +++ b/compiler/tests/syntax/compare_mismatched_types.leo @@ -0,0 +1,3 @@ +function main() { + let a = -5i8 > 342u32; +} \ No newline at end of file diff --git a/compiler/tests/syntax/mod.rs b/compiler/tests/syntax/mod.rs index da0f980d90..7bba90206b 100644 --- a/compiler/tests/syntax/mod.rs +++ b/compiler/tests/syntax/mod.rs @@ -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); +}