diff --git a/compiler/ast/src/types/type_.rs b/compiler/ast/src/types/type_.rs index 8c341705e4..645e0de9ed 100644 --- a/compiler/ast/src/types/type_.rs +++ b/compiler/ast/src/types/type_.rs @@ -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"), diff --git a/compiler/passes/src/code_generation/visit_expressions.rs b/compiler/passes/src/code_generation/visit_expressions.rs index 6248219901..0f506b3956 100644 --- a/compiler/passes/src/code_generation/visit_expressions.rs +++ b/compiler/passes/src/code_generation/visit_expressions.rs @@ -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); diff --git a/compiler/passes/src/code_generation/visit_type.rs b/compiler/passes/src/code_generation/visit_type.rs index 556c8adb4f..45c02ea9af 100644 --- a/compiler/passes/src/code_generation/visit_type.rs +++ b/compiler/passes/src/code_generation/visit_type.rs @@ -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 @@ -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()) } diff --git a/tests/expectations/compiler/array/array_initialization_fail.out b/tests/expectations/compiler/array/array_initialization_fail.out index 8e4f9f1340..805f5cca7e 100644 --- a/tests/expectations/compiler/array/array_initialization_fail.out +++ b/tests/expectations/compiler/array/array_initialization_fail.out @@ -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" diff --git a/tests/expectations/compiler/expression/cast_fail.out b/tests/expectations/compiler/expression/cast_fail.out index 0d8efa675e..6c6a20e0b3 100644 --- a/tests/expectations/compiler/expression/cast_fail.out +++ b/tests/expectations/compiler/expression/cast_fail.out @@ -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" diff --git a/tests/expectations/compiler/finalize/get_incorrect_type_fail.out b/tests/expectations/compiler/finalize/get_incorrect_type_fail.out index 41cc868242..93625fcc1a 100644 --- a/tests/expectations/compiler/finalize/get_incorrect_type_fail.out +++ b/tests/expectations/compiler/finalize/get_incorrect_type_fail.out @@ -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" diff --git a/tests/expectations/compiler/statements/assign_ternary.out b/tests/expectations/compiler/statements/assign_ternary.out index 48e2ae793b..338526c37d 100644 --- a/tests/expectations/compiler/statements/assign_ternary.out +++ b/tests/expectations/compiler/statements/assign_ternary.out @@ -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" diff --git a/tests/expectations/compiler/tuple/declare_fail.out b/tests/expectations/compiler/tuple/declare_fail.out index 9c81abf0ef..1c9e81a1b0 100644 --- a/tests/expectations/compiler/tuple/declare_fail.out +++ b/tests/expectations/compiler/tuple/declare_fail.out @@ -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" diff --git a/tests/expectations/compiler/tuple/return_statement_fail.out b/tests/expectations/compiler/tuple/return_statement_fail.out index 5e3c5ad3c4..4fc1c195e3 100644 --- a/tests/expectations/compiler/tuple/return_statement_fail.out +++ b/tests/expectations/compiler/tuple/return_statement_fail.out @@ -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" diff --git a/tests/expectations/compiler/tuple/type_fail.out b/tests/expectations/compiler/tuple/type_fail.out index 8dc2824c18..a06ec4576a 100644 --- a/tests/expectations/compiler/tuple/type_fail.out +++ b/tests/expectations/compiler/tuple/type_fail.out @@ -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" diff --git a/tests/tests/compiler/tuple/declare_fail.leo b/tests/tests/compiler/tuple/declare_fail.leo index 08a69fbe8d..674eb87bd5 100644 --- a/tests/tests/compiler/tuple/declare_fail.leo +++ b/tests/tests/compiler/tuple/declare_fail.leo @@ -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); } diff --git a/tests/tests/compiler/tuple/type_fail.leo b/tests/tests/compiler/tuple/type_fail.leo index 68da9ccbb3..aacf8e50ea 100644 --- a/tests/tests/compiler/tuple/type_fail.leo +++ b/tests/tests/compiler/tuple/type_fail.leo @@ -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); }