Skip to content

Commit

Permalink
Merge pull request #28380 from ProvableHQ/boolean
Browse files Browse the repository at this point in the history
Display Type::Boolean as `bool`, not `boolean`.
  • Loading branch information
d0cd authored Oct 7, 2024
2 parents b391f51 + 2bbff6d commit 0d2eb02
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion compiler/ast/src/types/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl fmt::Display for Type {
match *self {
Type::Address => write!(f, "address"),
Type::Array(ref array_type) => write!(f, "{array_type}"),
Type::Boolean => write!(f, "boolean"),
Type::Boolean => write!(f, "bool"),
Type::Field => write!(f, "field"),
Type::Future(ref future_type) => write!(f, "{future_type}"),
Type::Group => write!(f, "group"),
Expand Down
6 changes: 4 additions & 2 deletions compiler/passes/src/code_generation/visit_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ impl<'a> CodeGenerator<'a> {
// Increment the register counter.
self.next_register += 1;

let cast_instruction =
format!(" cast {expression_operand} into {destination_register} as {};\n", input.type_);
let cast_instruction = format!(
" cast {expression_operand} into {destination_register} as {};\n",
Self::visit_type(&input.type_)
);

// Concatenate the instructions.
instructions.push_str(&cast_instruction);
Expand Down
5 changes: 4 additions & 1 deletion compiler/passes/src/code_generation/visit_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ impl<'a> CodeGenerator<'a> {
pub(crate) fn visit_type(input: &Type) -> String {
match input {
Type::Address
| Type::Boolean
| Type::Field
| Type::Group
| Type::Scalar
Expand All @@ -32,6 +31,10 @@ impl<'a> CodeGenerator<'a> {
| Type::Composite(..)
| Type::Identifier(..)
| Type::Integer(..) => format!("{input}"),
Type::Boolean => {
// Leo calls this just `bool`, which isn't what we need.
"boolean".into()
}
Type::Array(array_type) => {
format!("[{}; {}u32]", Self::visit_type(array_type.element_type()), array_type.length())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372003]: Expected type `[boolean; 8]` but type `[boolean; 7]` was found\n --> compiler-test:5:16\n |\n 5 | return [a, a, a, a, a, a, a];\n | ^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372003]: Expected type `u8` but type `u32` was found\n --> compiler-test:9:52\n |\n 9 | return [1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u32];\n | ^^^^\n"
- "Error [ETYC0372003]: Expected type `[bool; 8]` but type `[bool; 7]` was found\n --> compiler-test:5:16\n |\n 5 | return [a, a, a, a, a, a, a];\n | ^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372003]: Expected type `u8` but type `u32` was found\n --> compiler-test:9:52\n |\n 9 | return [1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u32];\n | ^^^^\n"
2 changes: 1 addition & 1 deletion tests/expectations/compiler/expression/cast_fail.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372045]: Strings are not yet supported.\n --> compiler-test:13:9\n |\n 13 | let b: string = a as string;\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, boolean, address`, but got `string`\n --> compiler-test:13:25\n |\n 13 | let b: string = a as string;\n | ^^^^^^^^^^^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, boolean, address`, but got `Foo`\n --> compiler-test:16:24\n |\n 16 | let d: field = c as field;\n | ^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, boolean, address`, but got `(field,field)`\n --> compiler-test:19:24\n |\n 19 | let f: field = e as field;\n | ^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, boolean, address`, but got `(field => field)`\n --> compiler-test:25:24\n |\n 25 | let b: field = balances as field;\n | ^^^^^^^^\n"
- "Error [ETYC0372045]: Strings are not yet supported.\n --> compiler-test:13:9\n |\n 13 | let b: string = a as string;\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, bool, address`, but got `string`\n --> compiler-test:13:25\n |\n 13 | let b: string = a as string;\n | ^^^^^^^^^^^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, bool, address`, but got `Foo`\n --> compiler-test:16:24\n |\n 16 | let d: field = c as field;\n | ^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, bool, address`, but got `(field,field)`\n --> compiler-test:19:24\n |\n 19 | let f: field = e as field;\n | ^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, bool, address`, but got `(field => field)`\n --> compiler-test:25:24\n |\n 25 | let b: field = balances as field;\n | ^^^^^^^^\n"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372031]: A mapping's value cannot be a record\n --> compiler-test:10:5\n |\n 10 | mapping tokens: address => Token;\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372003]: Expected type `address` but type `boolean` was found\n --> compiler-test:17:30\n |\n 17 | Mapping::get(tokens, true);\n | ^^^^\nError [ETYC0372003]: Expected type `address` but type `boolean` was found\n --> compiler-test:18:20\n |\n 18 | tokens.get(true);\n | ^^^^\nError [ETYC0372003]: Expected type `address` but type `u8` was found\n --> compiler-test:19:31\n |\n 19 | Mapping::get(amounts, 1u8);\n | ^^^\nError [ETYC0372003]: Expected type `address` but type `u8` was found\n --> compiler-test:20:21\n |\n 20 | amounts.get(1u8);\n | ^^^\n"
- "Error [ETYC0372031]: A mapping's value cannot be a record\n --> compiler-test:10:5\n |\n 10 | mapping tokens: address => Token;\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372003]: Expected type `address` but type `bool` was found\n --> compiler-test:17:30\n |\n 17 | Mapping::get(tokens, true);\n | ^^^^\nError [ETYC0372003]: Expected type `address` but type `bool` was found\n --> compiler-test:18:20\n |\n 18 | tokens.get(true);\n | ^^^^\nError [ETYC0372003]: Expected type `address` but type `u8` was found\n --> compiler-test:19:31\n |\n 19 | Mapping::get(amounts, 1u8);\n | ^^^\nError [ETYC0372003]: Expected type `address` but type `u8` was found\n --> compiler-test:20:21\n |\n 20 | amounts.get(1u8);\n | ^^^\n"
2 changes: 1 addition & 1 deletion tests/expectations/compiler/statements/assign_ternary.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372003]: Expected type `boolean` but type `u32` was found\n --> compiler-test:5:30\n |\n 5 | let x: bool = true ? x: true;\n | ^\nError [EAST0372009]: variable `x` shadowed by\n --> compiler-test:5:13\n |\n 5 | let x: bool = true ? x: true;\n | ^\nError [ETYC0372083]: A program must have at least one transition function.\n --> compiler-test:1:1\n |\n 1 | \n 2 | \n 3 | program test.aleo { \n | ^^^^^^^^^^^^\n"
- "Error [ETYC0372003]: Expected type `bool` but type `u32` was found\n --> compiler-test:5:30\n |\n 5 | let x: bool = true ? x: true;\n | ^\nError [EAST0372009]: variable `x` shadowed by\n --> compiler-test:5:13\n |\n 5 | let x: bool = true ? x: true;\n | ^\nError [ETYC0372083]: A program must have at least one transition function.\n --> compiler-test:1:1\n |\n 1 | \n 2 | \n 3 | program test.aleo { \n | ^^^^^^^^^^^^\n"
2 changes: 1 addition & 1 deletion tests/expectations/compiler/tuple/declare_fail.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372003]: Expected type `boolean` but type `u64` was found\n --> compiler-test:5:35\n |\n 5 | let t: (bool, bool) = (a, 1u64); // We should be declaring to a boolean, not a u64.\n | ^^^^\n"
- "Error [ETYC0372003]: Expected type `bool` but type `u64` was found\n --> compiler-test:5:35\n |\n 5 | let t: (bool, bool) = (a, 1u64); // We should be declaring to a bool, not a u64.\n | ^^^^\n"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372003]: Expected type `u64` but type `boolean` was found\n --> compiler-test:7:24\n |\n 7 | return (t.0, t.1); // The second element should be type u64 as in the function declaration.\n | ^\n"
- "Error [ETYC0372003]: Expected type `u64` but type `bool` was found\n --> compiler-test:7:24\n |\n 7 | return (t.0, t.1); // The second element should be type u64 as in the function declaration.\n | ^\n"
2 changes: 1 addition & 1 deletion tests/expectations/compiler/tuple/type_fail.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372003]: Expected type `u64` but type `boolean` was found\n --> compiler-test:5:34\n |\n 5 | let t: (bool, u64) = (a, b); // We should expect a boolean, not a u64.\n | ^\nError [ETYC0372003]: Expected type `boolean` but type `u64` was found\n --> compiler-test:7:24\n |\n 7 | return (t.0, t.1);\n | ^\n"
- "Error [ETYC0372003]: Expected type `u64` but type `bool` was found\n --> compiler-test:5:34\n |\n 5 | let t: (bool, u64) = (a, b); // We should expect a bool, not a u64.\n | ^\nError [ETYC0372003]: Expected type `bool` but type `u64` was found\n --> compiler-test:7:24\n |\n 7 | return (t.0, t.1);\n | ^\n"
2 changes: 1 addition & 1 deletion tests/tests/compiler/tuple/declare_fail.leo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expectation: Fail

program test.aleo {
transition main(a: bool, b: bool) -> (bool, bool) {
let t: (bool, bool) = (a, 1u64); // We should be declaring to a boolean, not a u64.
let t: (bool, bool) = (a, 1u64); // We should be declaring to a bool, not a u64.

return (t.0, t.1);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/compiler/tuple/type_fail.leo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expectation: Fail

program test.aleo {
transition main(a: bool, b: bool) -> (bool, bool) {
let t: (bool, u64) = (a, b); // We should expect a boolean, not a u64.
let t: (bool, u64) = (a, b); // We should expect a bool, not a u64.

return (t.0, t.1);
}
Expand Down

0 comments on commit 0d2eb02

Please sign in to comment.