From c16a93ab44d338980b343d6c03d78c244f515f76 Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Sat, 2 Jul 2022 18:15:18 -0700 Subject: [PATCH] removes <, <=, >, >= for address type --- .../passes/src/type_checker/check_expressions.rs | 10 +++------- .../src/errors/type_checker/type_checker_error.rs | 7 +++++++ tests/compiler/address/equal.leo | 1 - tests/compiler/address/gt_fail.leo | 12 ++++++++++++ tests/compiler/address/gte_fail.leo | 12 ++++++++++++ tests/compiler/address/lt_fail.leo | 12 ++++++++++++ tests/compiler/address/lte_fail.leo | 12 ++++++++++++ .../expectations/compiler/compiler/address/equal.out | 1 - .../compiler/compiler/address/gt_fail.out | 5 +++++ .../compiler/compiler/address/gte_fail.out | 5 +++++ .../compiler/compiler/address/lt_fail.out | 5 +++++ .../compiler/compiler/address/lte_fail.out | 5 +++++ 12 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 tests/compiler/address/gt_fail.leo create mode 100644 tests/compiler/address/gte_fail.leo create mode 100644 tests/compiler/address/lt_fail.leo create mode 100644 tests/compiler/address/lte_fail.leo create mode 100644 tests/expectations/compiler/compiler/address/gt_fail.out create mode 100644 tests/expectations/compiler/compiler/address/gte_fail.out create mode 100644 tests/expectations/compiler/compiler/address/lt_fail.out create mode 100644 tests/expectations/compiler/compiler/address/lte_fail.out diff --git a/compiler/passes/src/type_checker/check_expressions.rs b/compiler/passes/src/type_checker/check_expressions.rs index c7b740f8ff..9c50799563 100644 --- a/compiler/passes/src/type_checker/check_expressions.rs +++ b/compiler/passes/src/type_checker/check_expressions.rs @@ -326,13 +326,9 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> { let t2 = self.visit_expression(&input.right, &None); match (t1, t2) { - (Some(Type::Address), t2) => { - // Assert rhs is address. - self.assert_expected_type(&t2, Type::Address, input.left.span()); - } - (t1, Some(Type::Address)) => { - // Assert lhs is address. - self.assert_expected_type(&t1, Type::Address, input.right.span()); + (Some(Type::Address), _) | (_, Some(Type::Address)) => { + // Emit an error for address comparison. + self.handler.emit_err(TypeCheckerError::compare_address(input.span()).into()); } (Some(Type::Field), t2) => { // Assert rhs is field. diff --git a/leo/errors/src/errors/type_checker/type_checker_error.rs b/leo/errors/src/errors/type_checker/type_checker_error.rs index 159b056161..e2c33bfcce 100644 --- a/leo/errors/src/errors/type_checker/type_checker_error.rs +++ b/leo/errors/src/errors/type_checker/type_checker_error.rs @@ -264,4 +264,11 @@ create_messages!( msg: format!("The field `{name}` in a `record` must have type `{type_}`."), help: None, } + + @formatted + compare_address { + args: (), + msg: format!("Comparison `<, <=, >, >=` is not supported for the address type."), + help: None, + } ); diff --git a/tests/compiler/address/equal.leo b/tests/compiler/address/equal.leo index 910fdb1290..540222ac69 100644 --- a/tests/compiler/address/equal.leo +++ b/tests/compiler/address/equal.leo @@ -3,7 +3,6 @@ namespace: Compile expectation: Pass input_file: - inputs/address1.in - - inputs/address2.in */ function main(x: address) -> bool { diff --git a/tests/compiler/address/gt_fail.leo b/tests/compiler/address/gt_fail.leo new file mode 100644 index 0000000000..aee889f08d --- /dev/null +++ b/tests/compiler/address/gt_fail.leo @@ -0,0 +1,12 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/address1.in +*/ + +function main(x: address) -> bool { + const sender: address = aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta; + + return x > sender; +} diff --git a/tests/compiler/address/gte_fail.leo b/tests/compiler/address/gte_fail.leo new file mode 100644 index 0000000000..bdfa67ef28 --- /dev/null +++ b/tests/compiler/address/gte_fail.leo @@ -0,0 +1,12 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/address1.in +*/ + +function main(x: address) -> bool { + const sender: address = aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta; + + return x >= sender; +} diff --git a/tests/compiler/address/lt_fail.leo b/tests/compiler/address/lt_fail.leo new file mode 100644 index 0000000000..bdeccb7321 --- /dev/null +++ b/tests/compiler/address/lt_fail.leo @@ -0,0 +1,12 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/address1.in +*/ + +function main(x: address) -> bool { + const sender: address = aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta; + + return x < sender; +} diff --git a/tests/compiler/address/lte_fail.leo b/tests/compiler/address/lte_fail.leo new file mode 100644 index 0000000000..11c4a31941 --- /dev/null +++ b/tests/compiler/address/lte_fail.leo @@ -0,0 +1,12 @@ +/* +namespace: Compile +expectation: Fail +input_file: + - inputs/address1.in +*/ + +function main(x: address) -> bool { + const sender: address = aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta; + + return x <= sender; +} diff --git a/tests/expectations/compiler/compiler/address/equal.out b/tests/expectations/compiler/compiler/address/equal.out index f3449a1433..52f854ffba 100644 --- a/tests/expectations/compiler/compiler/address/equal.out +++ b/tests/expectations/compiler/compiler/address/equal.out @@ -4,6 +4,5 @@ expectation: Pass outputs: - output: - initial_input_ast: 03e9df3bd1409f4af9e2a7f55130bc52f27d41f32a624ffa27f0ab114bf6fbf4 - - initial_input_ast: 9a0d83e67799f28ec6613d9aac9d921aea81eebb68c9682de33c69036c4a924f initial_ast: ea3c9a73110ccc7684863543cf563ec78349402c460a75317b776af11d46f781 symbol_table: 18395a136ea969d319cc4c12c59bb7a590a1b11339375240700d7c87f26b1d5d diff --git a/tests/expectations/compiler/compiler/address/gt_fail.out b/tests/expectations/compiler/compiler/address/gt_fail.out new file mode 100644 index 0000000000..fc072e2acf --- /dev/null +++ b/tests/expectations/compiler/compiler/address/gt_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [ETYC0372025]: Comparison `<, <=, >, >=` is not supported for the address type.\n --> compiler-test:6:12\n |\n 6 | return x > sender;\n | ^^^^^^^^^^\n" diff --git a/tests/expectations/compiler/compiler/address/gte_fail.out b/tests/expectations/compiler/compiler/address/gte_fail.out new file mode 100644 index 0000000000..16769c5c3b --- /dev/null +++ b/tests/expectations/compiler/compiler/address/gte_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [ETYC0372025]: Comparison `<, <=, >, >=` is not supported for the address type.\n --> compiler-test:6:12\n |\n 6 | return x >= sender;\n | ^^^^^^^^^^^\n" diff --git a/tests/expectations/compiler/compiler/address/lt_fail.out b/tests/expectations/compiler/compiler/address/lt_fail.out new file mode 100644 index 0000000000..c8bc9150b0 --- /dev/null +++ b/tests/expectations/compiler/compiler/address/lt_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [ETYC0372025]: Comparison `<, <=, >, >=` is not supported for the address type.\n --> compiler-test:6:12\n |\n 6 | return x < sender;\n | ^^^^^^^^^^\n" diff --git a/tests/expectations/compiler/compiler/address/lte_fail.out b/tests/expectations/compiler/compiler/address/lte_fail.out new file mode 100644 index 0000000000..30ab261bfc --- /dev/null +++ b/tests/expectations/compiler/compiler/address/lte_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [ETYC0372025]: Comparison `<, <=, >, >=` is not supported for the address type.\n --> compiler-test:6:12\n |\n 6 | return x <= sender;\n | ^^^^^^^^^^^\n"