removes <, <=, >, >= for address type

This commit is contained in:
collin 2022-07-02 18:15:18 -07:00
parent bf8ca5abc4
commit c16a93ab44
12 changed files with 78 additions and 9 deletions

View File

@ -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.

View File

@ -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,
}
);

View File

@ -3,7 +3,6 @@ namespace: Compile
expectation: Pass
input_file:
- inputs/address1.in
- inputs/address2.in
*/
function main(x: address) -> bool {

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -4,6 +4,5 @@ expectation: Pass
outputs:
- output:
- initial_input_ast: 03e9df3bd1409f4af9e2a7f55130bc52f27d41f32a624ffa27f0ab114bf6fbf4
- initial_input_ast: 9a0d83e67799f28ec6613d9aac9d921aea81eebb68c9682de33c69036c4a924f
initial_ast: ea3c9a73110ccc7684863543cf563ec78349402c460a75317b776af11d46f781
symbol_table: 18395a136ea969d319cc4c12c59bb7a590a1b11339375240700d7c87f26b1d5d

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"