diff --git a/compiler/ast/src/expressions/cast.rs b/compiler/ast/src/expressions/cast.rs new file mode 100644 index 0000000000..a39fc09474 --- /dev/null +++ b/compiler/ast/src/expressions/cast.rs @@ -0,0 +1,38 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use super::*; + +use crate::Type; + +/// A cast expression, e.g. `42u8 as u16`. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct CastExpression { + /// The expression to be casted, e.g.`42u8` in `42u8 as u16`. + pub expression: Box, + /// The type to be casted to, e.g. `u16` in `42u8 as u16`. + pub type_: Type, + /// Span of the entire cast `42u8 as u16`. + pub span: Span, +} + +impl fmt::Display for CastExpression { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "({} as {})", self.expression, self.type_) + } +} + +crate::simple_node_impl!(CastExpression); diff --git a/compiler/ast/src/expressions/mod.rs b/compiler/ast/src/expressions/mod.rs index 0627d161f0..b5f1b2b959 100644 --- a/compiler/ast/src/expressions/mod.rs +++ b/compiler/ast/src/expressions/mod.rs @@ -29,6 +29,9 @@ pub use binary::*; mod call; pub use call::*; +mod cast; +pub use cast::*; + mod struct_init; pub use struct_init::*; @@ -59,6 +62,8 @@ pub enum Expression { Binary(BinaryExpression), /// A call expression, e.g., `my_fun(args)`. Call(CallExpression), + /// A cast expression, e.g., `42u32 as u8`. + Cast(CastExpression), /// An expression constructing a struct like `Foo { bar: 42, baz }`. Struct(StructExpression), /// An expression of type "error". @@ -85,6 +90,7 @@ impl Node for Expression { Access(n) => n.span(), Binary(n) => n.span(), Call(n) => n.span(), + Cast(n) => n.span(), Struct(n) => n.span(), Err(n) => n.span(), Identifier(n) => n.span(), @@ -102,6 +108,7 @@ impl Node for Expression { Access(n) => n.set_span(span), Binary(n) => n.set_span(span), Call(n) => n.set_span(span), + Cast(n) => n.set_span(span), Struct(n) => n.set_span(span), Identifier(n) => n.set_span(span), Literal(n) => n.set_span(span), @@ -121,6 +128,7 @@ impl fmt::Display for Expression { Access(n) => n.fmt(f), Binary(n) => n.fmt(f), Call(n) => n.fmt(f), + Cast(n) => n.fmt(f), Struct(n) => n.fmt(f), Err(n) => n.fmt(f), Identifier(n) => n.fmt(f), diff --git a/compiler/ast/src/passes/consumer.rs b/compiler/ast/src/passes/consumer.rs index 6b0b751991..db6458ab66 100644 --- a/compiler/ast/src/passes/consumer.rs +++ b/compiler/ast/src/passes/consumer.rs @@ -28,6 +28,7 @@ pub trait ExpressionConsumer { Expression::Access(access) => self.consume_access(access), Expression::Binary(binary) => self.consume_binary(binary), Expression::Call(call) => self.consume_call(call), + Expression::Cast(cast) => self.consume_cast(cast), Expression::Struct(struct_) => self.consume_struct_init(struct_), Expression::Err(err) => self.consume_err(err), Expression::Identifier(identifier) => self.consume_identifier(identifier), @@ -45,6 +46,8 @@ pub trait ExpressionConsumer { fn consume_call(&mut self, _input: CallExpression) -> Self::Output; + fn consume_cast(&mut self, _input: CastExpression) -> Self::Output; + fn consume_struct_init(&mut self, _input: StructExpression) -> Self::Output; fn consume_err(&mut self, _input: ErrExpression) -> Self::Output { diff --git a/compiler/ast/src/passes/reconstructor.rs b/compiler/ast/src/passes/reconstructor.rs index 4c7e0bfb6d..80fc6aa91c 100644 --- a/compiler/ast/src/passes/reconstructor.rs +++ b/compiler/ast/src/passes/reconstructor.rs @@ -29,6 +29,7 @@ pub trait ExpressionReconstructor { Expression::Access(access) => self.reconstruct_access(access), Expression::Binary(binary) => self.reconstruct_binary(binary), Expression::Call(call) => self.reconstruct_call(call), + Expression::Cast(cast) => self.reconstruct_cast(cast), Expression::Struct(struct_) => self.reconstruct_struct_init(struct_), Expression::Err(err) => self.reconstruct_err(err), Expression::Identifier(identifier) => self.reconstruct_identifier(identifier), @@ -95,6 +96,17 @@ pub trait ExpressionReconstructor { ) } + fn reconstruct_cast(&mut self, input: CastExpression) -> (Expression, Self::AdditionalOutput) { + ( + Expression::Cast(CastExpression { + expression: Box::new(self.reconstruct_expression(*input.expression).0), + type_: input.type_, + span: input.span, + }), + Default::default(), + ) + } + fn reconstruct_struct_init(&mut self, input: StructExpression) -> (Expression, Self::AdditionalOutput) { (Expression::Struct(input), Default::default()) } diff --git a/compiler/ast/src/passes/visitor.rs b/compiler/ast/src/passes/visitor.rs index b536477ef5..bfeef4e208 100644 --- a/compiler/ast/src/passes/visitor.rs +++ b/compiler/ast/src/passes/visitor.rs @@ -30,6 +30,7 @@ pub trait ExpressionVisitor<'a> { Expression::Access(access) => self.visit_access(access, additional), Expression::Binary(binary) => self.visit_binary(binary, additional), Expression::Call(call) => self.visit_call(call, additional), + Expression::Cast(cast) => self.visit_cast(cast, additional), Expression::Struct(struct_) => self.visit_struct_init(struct_, additional), Expression::Err(err) => self.visit_err(err, additional), Expression::Identifier(identifier) => self.visit_identifier(identifier, additional), @@ -73,6 +74,11 @@ pub trait ExpressionVisitor<'a> { Default::default() } + fn visit_cast(&mut self, input: &'a CastExpression, additional: &Self::AdditionalInput) -> Self::Output { + self.visit_expression(&input.expression, additional); + Default::default() + } + fn visit_struct_init(&mut self, _input: &'a StructExpression, _additional: &Self::AdditionalInput) -> Self::Output { Default::default() } diff --git a/compiler/parser/src/parser/expression.rs b/compiler/parser/src/parser/expression.rs index 9a35025e26..fed10cd945 100644 --- a/compiler/parser/src/parser/expression.rs +++ b/compiler/parser/src/parser/expression.rs @@ -221,13 +221,21 @@ impl ParserContext<'_> { /// Returns an [`Expression`] AST node if the next tokens represent a /// binary exponentiation expression. /// - /// Otherwise, tries to parse the next token using [`parse_unary_expression`]. + /// Otherwise, tries to parse the next token using [`parse_cast_expression`]. fn parse_exponential_expression(&mut self) -> Result { - let mut expr = self.parse_unary_expression()?; + self.parse_bin_expr(&[Token::Pow], Self::parse_cast_expression) + } - if let Some(op) = self.eat_bin_op(&[Token::Pow]) { - let right = self.parse_exponential_expression()?; - expr = Self::bin_expr(expr, right, op); + /// Returns an [`Expression`] AST node if the next tokens represent a + /// cast expression. + /// + /// Otherwise, tries to parse the next token using [`parse_unary_expression`]. + fn parse_cast_expression(&mut self) -> Result { + let mut expr = self.parse_unary_expression()?; + if self.eat(&Token::As) { + let (type_, end_span) = self.parse_primitive_type()?; + let span = expr.span() + end_span; + expr = Expression::Cast(CastExpression { expression: Box::new(expr), type_, span }); } Ok(expr) diff --git a/compiler/parser/src/tokenizer/lexer.rs b/compiler/parser/src/tokenizer/lexer.rs index 5a23e52caf..f7e3510b6b 100644 --- a/compiler/parser/src/tokenizer/lexer.rs +++ b/compiler/parser/src/tokenizer/lexer.rs @@ -376,6 +376,7 @@ impl Token { match &*identifier { x if x.starts_with("aleo1") => Token::AddressLit(identifier), "address" => Token::Address, + "as" => Token::As, "assert" => Token::Assert, "assert_eq" => Token::AssertEq, "assert_neq" => Token::AssertNeq, diff --git a/compiler/parser/src/tokenizer/mod.rs b/compiler/parser/src/tokenizer/mod.rs index 4667d01d79..52889174c8 100644 --- a/compiler/parser/src/tokenizer/mod.rs +++ b/compiler/parser/src/tokenizer/mod.rs @@ -83,6 +83,7 @@ mod tests { test_ident 12345 address + as assert assert_eq assert_neq @@ -168,7 +169,7 @@ mod tests { assert_eq!( output, - r#""test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" test_ident 12345 address assert assert_eq assert_neq async bool const else false field finalize for function group i128 i64 i32 i16 i8 if in inline input let mut private program public return scalar self string struct test then transition true u128 u64 u32 u16 u8 console ! != && ( ) * ** + , - -> => _ . .. / : ; < <= = == > >= [ ] { { } } || ? @ // test + r#""test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" test_ident 12345 address as assert assert_eq assert_neq async bool const else false field finalize for function group i128 i64 i32 i16 i8 if in inline input let mut private program public return scalar self string struct test then transition true u128 u64 u32 u16 u8 console ! != && ( ) * ** + , - -> => _ . .. / : ; < <= = == > >= [ ] { { } } || ? @ // test /* test */ // "# ); }); diff --git a/compiler/parser/src/tokenizer/token.rs b/compiler/parser/src/tokenizer/token.rs index bbf2634c43..7fdad651a9 100644 --- a/compiler/parser/src/tokenizer/token.rs +++ b/compiler/parser/src/tokenizer/token.rs @@ -108,6 +108,7 @@ pub enum Token { Record, // Regular Keywords + As, Assert, AssertEq, AssertNeq, @@ -146,6 +147,7 @@ pub enum Token { /// because true and false are also boolean literals, which are different tokens from keywords. pub const KEYWORD_TOKENS: &[Token] = &[ Token::Address, + Token::As, Token::Assert, Token::AssertEq, Token::AssertNeq, @@ -199,6 +201,7 @@ impl Token { pub fn keyword_to_symbol(&self) -> Option { Some(match self { Token::Address => sym::address, + Token::As => sym::As, Token::Assert => sym::assert, Token::AssertEq => sym::assert_eq, Token::AssertNeq => sym::assert_neq, @@ -331,6 +334,7 @@ impl fmt::Display for Token { U128 => write!(f, "u128"), Record => write!(f, "record"), + As => write!(f, "as"), Assert => write!(f, "assert"), AssertEq => write!(f, "assert_eq"), AssertNeq => write!(f, "assert_neq"), diff --git a/compiler/passes/src/code_generation/visit_expressions.rs b/compiler/passes/src/code_generation/visit_expressions.rs index 19cde4a28c..a5378e68a4 100644 --- a/compiler/passes/src/code_generation/visit_expressions.rs +++ b/compiler/passes/src/code_generation/visit_expressions.rs @@ -22,6 +22,7 @@ use leo_ast::{ BinaryExpression, BinaryOperation, CallExpression, + CastExpression, ErrExpression, Expression, Identifier, @@ -50,6 +51,7 @@ impl<'a> CodeGenerator<'a> { Expression::Access(expr) => self.visit_access(expr), Expression::Binary(expr) => self.visit_binary(expr), Expression::Call(expr) => self.visit_call(expr), + Expression::Cast(expr) => self.visit_cast(expr), Expression::Struct(expr) => self.visit_struct_init(expr), Expression::Err(expr) => self.visit_err(expr), Expression::Identifier(expr) => self.visit_identifier(expr), @@ -127,6 +129,23 @@ impl<'a> CodeGenerator<'a> { (destination_register, instructions) } + fn visit_cast(&mut self, input: &'a CastExpression) -> (String, String) { + let (expression_operand, expression_instructions) = self.visit_expression(&input.expression); + + let destination_register = format!("r{}", self.next_register); + let cast_instruction = + format!(" cast {expression_operand} into {destination_register} as {};\n", input.type_); + + // Increment the register counter. + self.next_register += 1; + + // Concatenate the instructions. + let mut instructions = expression_instructions; + instructions.push_str(&cast_instruction); + + (destination_register, instructions) + } + fn visit_unary(&mut self, input: &'a UnaryExpression) -> (String, String) { let (expression_operand, expression_instructions) = self.visit_expression(&input.receiver); diff --git a/compiler/passes/src/static_single_assignment/rename_expression.rs b/compiler/passes/src/static_single_assignment/rename_expression.rs index d14cbbb195..a93752981d 100644 --- a/compiler/passes/src/static_single_assignment/rename_expression.rs +++ b/compiler/passes/src/static_single_assignment/rename_expression.rs @@ -21,6 +21,7 @@ use leo_ast::{ AssociatedFunction, BinaryExpression, CallExpression, + CastExpression, Expression, ExpressionConsumer, Identifier, @@ -155,6 +156,22 @@ impl ExpressionConsumer for StaticSingleAssigner<'_> { (Expression::Identifier(place), statements) } + /// Consumes a cast expression, accumulating any statements that are generated. + fn consume_cast(&mut self, input: CastExpression) -> Self::Output { + // Reconstruct the expression being casted. + let (expression, mut statements) = self.consume_expression(*input.expression); + + // Construct and accumulate a unique assignment statement storing the result of the cast expression. + let (place, statement) = self.assigner.unique_simple_assign_statement(Expression::Cast(CastExpression { + expression: Box::new(expression), + type_: input.type_, + span: input.span, + })); + statements.push(statement); + + (Expression::Identifier(place), statements) + } + /// Consumes a struct initialization expression with renamed variables, accumulating any statements that are generated. fn consume_struct_init(&mut self, input: StructExpression) -> Self::Output { let mut statements = Vec::new(); diff --git a/compiler/passes/src/type_checking/check_expressions.rs b/compiler/passes/src/type_checking/check_expressions.rs index 11185306e3..bbd9b673a1 100644 --- a/compiler/passes/src/type_checking/check_expressions.rs +++ b/compiler/passes/src/type_checking/check_expressions.rs @@ -512,6 +512,20 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> { } } + fn visit_cast(&mut self, input: &'a CastExpression, expected: &Self::AdditionalInput) -> Self::Output { + // Check that the target type of the cast expression is a castable type. + let target_type = Some(input.type_.clone()); + self.assert_castable_type(&target_type, input.span()); + + // Check that the expression type is a primitive type. + let expression_type = self.visit_expression(&input.expression, &None); + self.assert_castable_type(&expression_type, input.expression.span()); + + // Check that the expected type matches the target type. + // Note that this unwrap is safe since target_type is always `Some`. + Some(self.assert_and_return_type(target_type.unwrap(), expected, input.span())) + } + fn visit_struct_init(&mut self, input: &'a StructExpression, additional: &Self::AdditionalInput) -> Self::Output { let struct_ = self.symbol_table.borrow().lookup_struct(input.name.name).cloned(); if let Some(struct_) = struct_ { diff --git a/compiler/passes/src/type_checking/checker.rs b/compiler/passes/src/type_checking/checker.rs index 4d20f2902a..8baf15ddd2 100644 --- a/compiler/passes/src/type_checking/checker.rs +++ b/compiler/passes/src/type_checking/checker.rs @@ -49,6 +49,8 @@ pub struct TypeChecker<'a> { pub(crate) is_return: bool, } +const ADDRESS_TYPE: Type = Type::Address; + const BOOLEAN_TYPE: Type = Type::Boolean; const FIELD_TYPE: Type = Type::Field; @@ -290,7 +292,7 @@ impl<'a> TypeChecker<'a> { ) } - /// Emits an error to the handler if the given type is not a field, group, scalar or integer. + /// Emits an error to the handler if the given type is not a field, group, scalar, integer, or boolean. pub(crate) fn assert_field_group_scalar_int_type(&self, type_: &Option, span: Span) { self.check_type( |type_: &Type| { @@ -302,6 +304,31 @@ impl<'a> TypeChecker<'a> { ) } + /// Emits an error to the handler if the given type is not a field, group, scalar, integer, boolean, or address. + pub(crate) fn assert_castable_type(&self, type_: &Option, span: Span) { + self.check_type( + |type_: &Type| { + FIELD_TYPE.eq(type_) + | GROUP_TYPE.eq(type_) + | SCALAR_TYPE.eq(type_) + | INT_TYPES.contains(type_) + | BOOLEAN_TYPE.eq(type_) + | ADDRESS_TYPE.eq(type_) + }, + format!( + "{}, {}, {}, {}, {}, {}", + FIELD_TYPE, + GROUP_TYPE, + SCALAR_TYPE, + types_to_string(&INT_TYPES), + BOOLEAN_TYPE, + ADDRESS_TYPE + ), + type_, + span, + ) + } + /// Type checks the inputs to an associated constant and returns the expected output type. pub(crate) fn get_core_constant(&self, type_: &Type, constant: &Identifier) -> Option { if let Type::Identifier(ident) = type_ { @@ -356,7 +383,7 @@ impl<'a> TypeChecker<'a> { let check_not_mapping_tuple_err_unit = |type_: &Option, span: &Span| { self.check_type( |type_: &Type| !matches!(type_, Type::Mapping(_) | Type::Tuple(_) | Type::Err | Type::Unit), - "address, boolean, field, group, struct, integer, scalar, struct".to_string(), + "address, bool, field, group, struct, integer, scalar, struct".to_string(), type_, *span, ); @@ -379,7 +406,7 @@ impl<'a> TypeChecker<'a> { | Type::Unit ) }, - "address, boolean, field, group, struct, integer, scalar, struct".to_string(), + "address, bool, field, group, struct, integer, scalar, struct".to_string(), type_, *span, ); @@ -400,7 +427,7 @@ impl<'a> TypeChecker<'a> { | Type::Unit ) }, - "address, boolean, field, group, struct, integer, scalar, struct".to_string(), + "address, bool, field, group, struct, integer, scalar, struct".to_string(), type_, *span, ); diff --git a/compiler/span/src/symbol.rs b/compiler/span/src/symbol.rs index f347ed7852..57beba56ce 100644 --- a/compiler/span/src/symbol.rs +++ b/compiler/span/src/symbol.rs @@ -201,6 +201,7 @@ symbols! { True: "true", // general keywords + As: "as", assert, assert_eq, assert_neq, diff --git a/tests/expectations/compiler/core/algorithms/bhp1024_commit_to_group.out b/tests/expectations/compiler/core/algorithms/bhp1024_commit_to_group.out index c5f74c915c..b4801c256a 100644 --- a/tests/expectations/compiler/core/algorithms/bhp1024_commit_to_group.out +++ b/tests/expectations/compiler/core/algorithms/bhp1024_commit_to_group.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 896305425070c637fba01f575eacd09304754c578cbefab4cf761222a6508bc1 - unrolled_ast: 896305425070c637fba01f575eacd09304754c578cbefab4cf761222a6508bc1 - ssa_ast: d1ba294f32123bdf9cd9e31c674b444596c27e9720933cf12e68d37a208a8746 - flattened_ast: 8c0b1aefb1db55471ef38223f334e1ec5855f338dd8402e42e76847067330e6b - inlined_ast: 8c0b1aefb1db55471ef38223f334e1ec5855f338dd8402e42e76847067330e6b - dce_ast: 6b1b7b1341b3c7b9478db64e938538f33c71535f9f530c9e8b37f99a5da69a27 + - - initial_ast: 30af76fe81f9f4708fd950b4e9969ccd98848fd19ed0186039595d1e5a27844d + unrolled_ast: 30af76fe81f9f4708fd950b4e9969ccd98848fd19ed0186039595d1e5a27844d + ssa_ast: 802c704ffee618f1ba6cc45b03dc38d8804d97291247332ce2b3d6fe3013db09 + flattened_ast: 73ca3b7c2d21074790829863c66cb65d61a558e7ce78a95825836fe97a6a82ad + inlined_ast: 73ca3b7c2d21074790829863c66cb65d61a558e7ce78a95825836fe97a6a82ad + dce_ast: e49f3a349238d24bf30e10bbe2b77cd0d55b1cd797076b3f14e2c80ba744e3f2 bytecode: 83cd9a0a063adab9de89253b1a5be0b4bbdc04a2a73a62a03fc1dd1639a4fbbf warnings: "" diff --git a/tests/expectations/compiler/core/algorithms/bhp256_commit_to_group.out b/tests/expectations/compiler/core/algorithms/bhp256_commit_to_group.out index d618c3cea1..3a00f89469 100644 --- a/tests/expectations/compiler/core/algorithms/bhp256_commit_to_group.out +++ b/tests/expectations/compiler/core/algorithms/bhp256_commit_to_group.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 9f01bc3bda296633a3f3320de7bb338431b79c4aa8d0145d71a71ff2b8a27a41 - unrolled_ast: 9f01bc3bda296633a3f3320de7bb338431b79c4aa8d0145d71a71ff2b8a27a41 - ssa_ast: c65e3149273b96856d3abf9619d9cc43d47b487f4b66e50a7428fad1de2ab604 - flattened_ast: 5f101a3a7e8eed1d2c89ab95fdce26022f1dbb697aa217402c56d2a1038613b2 - inlined_ast: 5f101a3a7e8eed1d2c89ab95fdce26022f1dbb697aa217402c56d2a1038613b2 - dce_ast: 11a6df9f5287fb118835a9dd942e4b6efe8831ac33758ec9063060812814738a + - - initial_ast: f030d2195ae4734f63d45b6723f0457a91614633bcd13c16b9acb5066ebf6aea + unrolled_ast: f030d2195ae4734f63d45b6723f0457a91614633bcd13c16b9acb5066ebf6aea + ssa_ast: 8193fef9bd81d561321c13def2fd31371602f909a8d2194fc95d4bc395bde4e6 + flattened_ast: 407c3d2fabd0d6c9f9c9ca5b68cb827876a5f9a3f45007b857888624922bf143 + inlined_ast: 407c3d2fabd0d6c9f9c9ca5b68cb827876a5f9a3f45007b857888624922bf143 + dce_ast: b950d25b2c99ceb0c1e3936a1bd9e06c657aebe53cd244282b0964df020f50c8 bytecode: 7cbb302c804e8dcb41c04687fe6f45aa748c5b7c0821f3825d21b424a4f89828 warnings: "" diff --git a/tests/expectations/compiler/core/algorithms/bhp512_commit_to_group.out b/tests/expectations/compiler/core/algorithms/bhp512_commit_to_group.out index 53e41c61e1..99d7ed88b6 100644 --- a/tests/expectations/compiler/core/algorithms/bhp512_commit_to_group.out +++ b/tests/expectations/compiler/core/algorithms/bhp512_commit_to_group.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 1ab754cc68284ab6a0fbf48a680a3bee5bf7a4cd2dd2974c2c01df60d60fdf2d - unrolled_ast: 1ab754cc68284ab6a0fbf48a680a3bee5bf7a4cd2dd2974c2c01df60d60fdf2d - ssa_ast: db79040aceb7ce4ae604aa834ed6360b0ae3e9185dee126ea34d9f9b2ee6b866 - flattened_ast: 9ddad61b8b10c13c0d19c0bfb376d5004de8a2f97626cfffe49fc4c9764cb4f9 - inlined_ast: 9ddad61b8b10c13c0d19c0bfb376d5004de8a2f97626cfffe49fc4c9764cb4f9 - dce_ast: e40d682317cf6c3110564aa97420a58d155f7fa3d3dcff5e1d0f75ae56b76aa8 + - - initial_ast: f342b48a009f75911bf75408b5f4a5d50b30a932291c27c04764cc81a0b0e855 + unrolled_ast: f342b48a009f75911bf75408b5f4a5d50b30a932291c27c04764cc81a0b0e855 + ssa_ast: 9eb17d21f68e78390498fd934eb26409fda3af1e6812c5a0eecfbf7f47b78d75 + flattened_ast: 13557bcb68b63b1d1adf4190717cc1c63d0b8a31e6e9634c22a110b475383203 + inlined_ast: 13557bcb68b63b1d1adf4190717cc1c63d0b8a31e6e9634c22a110b475383203 + dce_ast: a94d5391be3d212a7fa4c2ff4eac66c10b8ce112c81112129c5fdd74c042f519 bytecode: 5bf36355b36caa6fcd510f195c79195a7991b45e037c7d6ffe9479f3c2bb89f6 warnings: "" diff --git a/tests/expectations/compiler/core/algorithms/bhp768_commit_to_group.out b/tests/expectations/compiler/core/algorithms/bhp768_commit_to_group.out index 8c4f345402..c2361d7e8f 100644 --- a/tests/expectations/compiler/core/algorithms/bhp768_commit_to_group.out +++ b/tests/expectations/compiler/core/algorithms/bhp768_commit_to_group.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 4d32007f979cf3ef268824dc68f4c321afd33104259497541c36b75aa7d5824d - unrolled_ast: 4d32007f979cf3ef268824dc68f4c321afd33104259497541c36b75aa7d5824d - ssa_ast: 33d5aaa45dbac16c88948ad934e829bc56f4eab6d2dd705742a972172c19af07 - flattened_ast: 97ffe1403034853d8baf7858bebfe80940330b7731c100e370ec814b56ee1e07 - inlined_ast: 97ffe1403034853d8baf7858bebfe80940330b7731c100e370ec814b56ee1e07 - dce_ast: 3dcbf6f804b2d25d13df32087a2383b366b5717426eea0d109845c73a0e369f4 + - - initial_ast: 332e75e208b648eb356d5d600becadcfc1aaff12a63f3a6ea60c97b18207a745 + unrolled_ast: 332e75e208b648eb356d5d600becadcfc1aaff12a63f3a6ea60c97b18207a745 + ssa_ast: 998455b42d1cc88d8318c6e1605c3e9953f91acfe26406c0d7090ac90b98c3e8 + flattened_ast: cd528fc82632fc44116b0c58f8688eb7e6b6aaf6bf23ce5053438db9f71a5265 + inlined_ast: cd528fc82632fc44116b0c58f8688eb7e6b6aaf6bf23ce5053438db9f71a5265 + dce_ast: d62b7eacb882bef890c5971a8bc9291f4860105e6c7cab3d068c4df06b809464 bytecode: aee0a49b3add5225dd3e0e2343805040b94c16916e51b3405924378f62eb9f36 warnings: "" diff --git a/tests/expectations/compiler/core/algorithms/pedersen_fail.out b/tests/expectations/compiler/core/algorithms/pedersen_fail.out index c20a6963e6..f48a0c644f 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen_fail.out +++ b/tests/expectations/compiler/core/algorithms/pedersen_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372007]: Expected one type from `address, boolean, field, group, struct, integer, scalar, struct`, but got `u128`\n --> compiler-test:5:50\n |\n 5 | let a: group = Pedersen64::hash_to_field(1u128); // Pedersen64 hash_to_field returns a field type\n | ^^^^^\nError [ETYC0372007]: Expected one type from `group`, but got `field`\n --> compiler-test:5:24\n |\n 5 | let a: group = Pedersen64::hash_to_field(1u128); // Pedersen64 hash_to_field returns a field type\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Error [ETYC0372007]: Expected one type from `address, bool, field, group, struct, integer, scalar, struct`, but got `u128`\n --> compiler-test:5:50\n |\n 5 | let a: group = Pedersen64::hash_to_field(1u128); // Pedersen64 hash_to_field returns a field type\n | ^^^^^\nError [ETYC0372007]: Expected one type from `group`, but got `field`\n --> compiler-test:5:24\n |\n 5 | let a: group = Pedersen64::hash_to_field(1u128); // Pedersen64 hash_to_field returns a field type\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" diff --git a/tests/expectations/compiler/expression/cast.out b/tests/expectations/compiler/expression/cast.out new file mode 100644 index 0000000000..fd073369d5 --- /dev/null +++ b/tests/expectations/compiler/expression/cast.out @@ -0,0 +1,12 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - - initial_ast: ec4ae9b108269fca4fb4ceec837aa77740fd43c36a8a5dceb5ac8f98341203e3 + unrolled_ast: ec4ae9b108269fca4fb4ceec837aa77740fd43c36a8a5dceb5ac8f98341203e3 + ssa_ast: 2f87f2a114c0db07e048f7d1b939620feb9fafe5d0b135787703639cd3f37732 + flattened_ast: 06c776ca0183829d9dd87d91d81b117ba1fdafb9101a097cf76e6e95f22fd10c + inlined_ast: 06c776ca0183829d9dd87d91d81b117ba1fdafb9101a097cf76e6e95f22fd10c + dce_ast: 57268c07cd44a0d3ffa45b6065fe9845c033115a39e54ae2cff650aba4e354d5 + bytecode: 3c8ea2338433747c1805ff0086031f7be0d253cf25b173de2f145945fdbf2c98 + warnings: "" diff --git a/tests/expectations/compiler/expression/cast_coersion.out b/tests/expectations/compiler/expression/cast_coersion.out new file mode 100644 index 0000000000..3e8edfde25 --- /dev/null +++ b/tests/expectations/compiler/expression/cast_coersion.out @@ -0,0 +1,12 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - - initial_ast: afe29d66a28151220f870b3a7f8a78543ebfc6427adf4eb5950b1bd574b02a9e + unrolled_ast: afe29d66a28151220f870b3a7f8a78543ebfc6427adf4eb5950b1bd574b02a9e + ssa_ast: 45a2cf824da09572b0958ad5ec799d80fe6192a441eefa9cb021f11c519f8585 + flattened_ast: 3426de3487eefb807450d2bbf9e21cc8530bc9b82e38c93758e889179ba4cad5 + inlined_ast: 3426de3487eefb807450d2bbf9e21cc8530bc9b82e38c93758e889179ba4cad5 + dce_ast: 3426de3487eefb807450d2bbf9e21cc8530bc9b82e38c93758e889179ba4cad5 + bytecode: 675912267b82b91bd854fa2ef169b85c74ecaac6b73a157d7e99818e256b53b1 + warnings: "" diff --git a/tests/expectations/compiler/expression/cast_fail.out b/tests/expectations/compiler/expression/cast_fail.out new file mode 100644 index 0000000000..af5064d352 --- /dev/null +++ b/tests/expectations/compiler/expression/cast_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [ETYC0372050]: 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" diff --git a/tests/expectations/compiler/integers/i128/operator_methods.out b/tests/expectations/compiler/integers/i128/operator_methods.out index 9c6dc84966..7507fb8efb 100644 --- a/tests/expectations/compiler/integers/i128/operator_methods.out +++ b/tests/expectations/compiler/integers/i128/operator_methods.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 6b89d3bab13e52897bf04b9235e31a3e5bfdab7fe60a2dcc9ab926be141abb4f - unrolled_ast: 6b89d3bab13e52897bf04b9235e31a3e5bfdab7fe60a2dcc9ab926be141abb4f - ssa_ast: 0b44d837ff2020c4a6ede3595577a20231ea57034673a0471fd73e6234ae6232 - flattened_ast: 20be84b5b3ee1bd280628f71c0d075cb74ff40ffa718d8b2efa58352ffd79fba - inlined_ast: 20be84b5b3ee1bd280628f71c0d075cb74ff40ffa718d8b2efa58352ffd79fba + - - initial_ast: 90711bfea326a87ea037470bc1d266309b79cf43b54c9b88264c91644ea2f611 + unrolled_ast: 90711bfea326a87ea037470bc1d266309b79cf43b54c9b88264c91644ea2f611 + ssa_ast: 591fcc16efc9970d8145fedaed2971bf1f025ba8a1df3b17189f905a32c1169f + flattened_ast: af95e362c8bbd5ff9c1f12418d31b1bd411f0e0820e7509009e7cf4a89a0edac + inlined_ast: af95e362c8bbd5ff9c1f12418d31b1bd411f0e0820e7509009e7cf4a89a0edac dce_ast: 1771d27db1197238272501b14e8d7da633f18a5c0454038b712cd107599450a5 bytecode: 3f9bcd59307e76bb9f1ec70f6b5aa9d7d279141fd0ac17f03e19ad42c64b292e warnings: "" diff --git a/tests/expectations/compiler/integers/i16/operator_methods.out b/tests/expectations/compiler/integers/i16/operator_methods.out index 0239a8d5a2..decfe40453 100644 --- a/tests/expectations/compiler/integers/i16/operator_methods.out +++ b/tests/expectations/compiler/integers/i16/operator_methods.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: eecbf39e1d25a542f6eeb36a50f49a96e432d424d6bed35676e9e3fa4d97aaa0 - unrolled_ast: eecbf39e1d25a542f6eeb36a50f49a96e432d424d6bed35676e9e3fa4d97aaa0 - ssa_ast: 17432df3d1c6504ce57a8ba77f2ab699bd250b44338db7cbb2061e7567822c9b - flattened_ast: 6cc1152fb17f0197e269366aa90378cf19b2495785d70da0db0789f455242b8f - inlined_ast: 6cc1152fb17f0197e269366aa90378cf19b2495785d70da0db0789f455242b8f + - - initial_ast: fe020d481a7875a659f18d68ce735f7cc48faa563fba2c03f8412a43d7e278aa + unrolled_ast: fe020d481a7875a659f18d68ce735f7cc48faa563fba2c03f8412a43d7e278aa + ssa_ast: efd392405ff78f1b928bd4b14297f2c72bea5967ac6e474956b9e773675dac26 + flattened_ast: cd8646240f3e311e51060aa7ebb1aa03877976efcfe38c7b3bb33662ee634476 + inlined_ast: cd8646240f3e311e51060aa7ebb1aa03877976efcfe38c7b3bb33662ee634476 dce_ast: fabfd09410dc36bf4c81828ff96c9353e78aa8b721cbb8870eda9dde7aa0c1d2 bytecode: 2ae0c269722de40ebea82115838ca6bc794e781954d9437afc1684c0f171847f warnings: "" diff --git a/tests/expectations/compiler/integers/i32/operator_methods.out b/tests/expectations/compiler/integers/i32/operator_methods.out index af0f42794b..186919d10f 100644 --- a/tests/expectations/compiler/integers/i32/operator_methods.out +++ b/tests/expectations/compiler/integers/i32/operator_methods.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 0975276579947ad8fb727d22e9861cda43a1c3938a30797eaa220de674cba792 - unrolled_ast: 0975276579947ad8fb727d22e9861cda43a1c3938a30797eaa220de674cba792 - ssa_ast: 7c116f6311daf0321afd5bacfe54252cf25030148239b75e20340f1d3616057d - flattened_ast: bbde81fbdb9bd53b73eaa0ec8a0c21b0c26b18695bb2f826af439d312856bd17 - inlined_ast: bbde81fbdb9bd53b73eaa0ec8a0c21b0c26b18695bb2f826af439d312856bd17 + - - initial_ast: b20fc0f09c06e7b67d2f5646d70dcef0bd26fe9c165f73bca01e4111780b6d5c + unrolled_ast: b20fc0f09c06e7b67d2f5646d70dcef0bd26fe9c165f73bca01e4111780b6d5c + ssa_ast: cb15b4b3436152b00cb11a2156ac30da33fb93cddfb045008a741c308af466b6 + flattened_ast: 59cb17e8174334e874f5c797a2027dbf9e41d3db2f327906dc9a35da9b4a0514 + inlined_ast: 59cb17e8174334e874f5c797a2027dbf9e41d3db2f327906dc9a35da9b4a0514 dce_ast: 751cf9bf0011f1b2cec9c30ba252e5fdb2cfb07b565f7d7d49d3ec46948d8d79 bytecode: 40661150b3b39dd341d29dab9771982c77efa03e028104d1965c1e2e2fbf3c28 warnings: "" diff --git a/tests/expectations/compiler/integers/i64/operator_methods.out b/tests/expectations/compiler/integers/i64/operator_methods.out index 601592522b..dae6a8169a 100644 --- a/tests/expectations/compiler/integers/i64/operator_methods.out +++ b/tests/expectations/compiler/integers/i64/operator_methods.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: aacae98aeedbd8eb16311d12874e2245ce8c205fbb67f7c5efdb8b3f71d4c605 - unrolled_ast: aacae98aeedbd8eb16311d12874e2245ce8c205fbb67f7c5efdb8b3f71d4c605 - ssa_ast: 7a9ea30b5ebc12987e117322db994faae028794aacc81ad91c48fdcab3c95b3b - flattened_ast: 4e635e9839a156e43a5b384f8236b4e5bfa0bd4b8628248b33bfd4fcdde51268 - inlined_ast: 4e635e9839a156e43a5b384f8236b4e5bfa0bd4b8628248b33bfd4fcdde51268 + - - initial_ast: ecfdedf45f2ded560ea22235dffc2d66a9854f3f195f348f641c118945ef04ab + unrolled_ast: ecfdedf45f2ded560ea22235dffc2d66a9854f3f195f348f641c118945ef04ab + ssa_ast: 0efd1e9bcb1d10f4f6e600d3e01d1d44daf7af3ad433c1124bffe55cd2f51b51 + flattened_ast: ea2ea988b88e2e9d1b7f6589caa25a3509767ee6f84031a9f3c47b46b6dea912 + inlined_ast: ea2ea988b88e2e9d1b7f6589caa25a3509767ee6f84031a9f3c47b46b6dea912 dce_ast: 4b8d95f79487158d586ee7a424d94666a27a3cec5506a20ea834045f13da9e28 bytecode: 94719443d1e9713563afa7861751ae6fac8380851db816055ed46c207a613efc warnings: "" diff --git a/tests/expectations/compiler/integers/i8/operator_methods.out b/tests/expectations/compiler/integers/i8/operator_methods.out index 3e5ce732e6..a62bed833f 100644 --- a/tests/expectations/compiler/integers/i8/operator_methods.out +++ b/tests/expectations/compiler/integers/i8/operator_methods.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 1cba72665d1102f804f3fccb2ebf73f76ed10f974675c216bb1f6bf20fff96c4 - unrolled_ast: 1cba72665d1102f804f3fccb2ebf73f76ed10f974675c216bb1f6bf20fff96c4 - ssa_ast: b7d9af462493e5cc8637349fa61366916adf499048543450c162727bf12273dd - flattened_ast: 29ed8496d287dcc3ef9cc9cb6d35e45dc6b986204704fc73db39b78380fe7d50 - inlined_ast: 29ed8496d287dcc3ef9cc9cb6d35e45dc6b986204704fc73db39b78380fe7d50 + - - initial_ast: 0a66acad482e7deaae054683e2cd33996e757aa1e64f1103a01fee9f766a3652 + unrolled_ast: 0a66acad482e7deaae054683e2cd33996e757aa1e64f1103a01fee9f766a3652 + ssa_ast: 73f5070c6d63ae87c10fd92adcdd718f744b9645925474a9d7e45e7c89602484 + flattened_ast: 5c1d3fa9c07c2abd710a10447259d4fcfc4ced843c0828940961b7683ed126b7 + inlined_ast: 5c1d3fa9c07c2abd710a10447259d4fcfc4ced843c0828940961b7683ed126b7 dce_ast: f8c8c8020a2b983010733d2ae27d2cec2cb379d74a92af8727cd5b75c48378b0 bytecode: faddd6204de19b830842ea34e1f218276b8e8914ecd7fdbfd4143b0f08d305c1 warnings: "" diff --git a/tests/expectations/compiler/integers/u128/operator_methods.out b/tests/expectations/compiler/integers/u128/operator_methods.out index a1b0719291..a8fcf76781 100644 --- a/tests/expectations/compiler/integers/u128/operator_methods.out +++ b/tests/expectations/compiler/integers/u128/operator_methods.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 547210f3b161436d3e94ed5f33a3d515c96cb558d6b7c2d88ebf46b094ea8065 - unrolled_ast: 547210f3b161436d3e94ed5f33a3d515c96cb558d6b7c2d88ebf46b094ea8065 - ssa_ast: 4e66aede3441b08af5970d8cc6c836767e05a2c7c51d4a2e829f306390bcf841 - flattened_ast: 47d4fe543e46da21be791a057d7f9d8ff47b433c8925b92d330a7a26f6765897 - inlined_ast: 47d4fe543e46da21be791a057d7f9d8ff47b433c8925b92d330a7a26f6765897 + - - initial_ast: aeb9628939a1d904effb0ea25447580072847577ec8279127c60647f489c6260 + unrolled_ast: aeb9628939a1d904effb0ea25447580072847577ec8279127c60647f489c6260 + ssa_ast: 3a5aedaf8fe63e29a38b3f26ee30df4b7e56d0a4b67d446b85d53d6c84d7e603 + flattened_ast: b883e5d349eb531a07321d12c57b47a4bb4b6433105aa2fb482cf314d1521f22 + inlined_ast: b883e5d349eb531a07321d12c57b47a4bb4b6433105aa2fb482cf314d1521f22 dce_ast: 5f23e1a070989119c1a28bce6e18b3edc5fc1811b05fbcc7852a054866f2a1a1 bytecode: a669206687d494820bada50c8468f052183b69cd778ff0ce870a370ac8ea7bf4 warnings: "" diff --git a/tests/expectations/compiler/integers/u16/operator_methods.out b/tests/expectations/compiler/integers/u16/operator_methods.out index 4a3b590ab3..5d7e61fecc 100644 --- a/tests/expectations/compiler/integers/u16/operator_methods.out +++ b/tests/expectations/compiler/integers/u16/operator_methods.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: f5b3b17bd093c0341f5bbe9d0718cd5b6c74912b533adde36f9c5da0ff6a6af6 - unrolled_ast: f5b3b17bd093c0341f5bbe9d0718cd5b6c74912b533adde36f9c5da0ff6a6af6 - ssa_ast: d87bf4a15278c93037efe57db3743f27fc09a08eba958612b24f8226db12a1a9 - flattened_ast: 35825530ad88a4714cf076b345a501380859366316436a02a7afc3c2fa6d6655 - inlined_ast: 35825530ad88a4714cf076b345a501380859366316436a02a7afc3c2fa6d6655 + - - initial_ast: c2774b14c3c8fe2f5adac3e6569b9447b7c79f4c90f6aed9eb635ccbee87e9eb + unrolled_ast: c2774b14c3c8fe2f5adac3e6569b9447b7c79f4c90f6aed9eb635ccbee87e9eb + ssa_ast: 1c6b1bed88cdfc61e81dc7986271c28e570762bd4cbf7dbfb7b9bd64a27e8ab2 + flattened_ast: 87af6378ea5610110a7a6f4c247739618657f7315fbb106d66a2e9f0635fbde7 + inlined_ast: 87af6378ea5610110a7a6f4c247739618657f7315fbb106d66a2e9f0635fbde7 dce_ast: 549ea2d966ca9b043d549740f7f4bbc67986dc9ce227257a1a629ae33ea3d5c0 bytecode: 842bf9cb4647adc6c67cecc1c36ec85f5a659d9245571869e10e93bb303ff343 warnings: "" diff --git a/tests/expectations/compiler/integers/u32/operator_methods.out b/tests/expectations/compiler/integers/u32/operator_methods.out index a1b24e82c0..f8f7165301 100644 --- a/tests/expectations/compiler/integers/u32/operator_methods.out +++ b/tests/expectations/compiler/integers/u32/operator_methods.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 4122e0f35832c94f02c0402ccd3e119d2959fa0622d853236aee221c9ce75321 - unrolled_ast: 4122e0f35832c94f02c0402ccd3e119d2959fa0622d853236aee221c9ce75321 - ssa_ast: f7da86e7baa8412cedcf072b206aa14bc9066783623248d66016bbdab5b2f609 - flattened_ast: ecca31afbdf9d9cc9576617e607fcc9e6abe332e627032ac0203f39e85421bbc - inlined_ast: ecca31afbdf9d9cc9576617e607fcc9e6abe332e627032ac0203f39e85421bbc + - - initial_ast: df68b369524adf6417661b438beafdfe21fbe3b2cd8b466cf8d256055cb13a90 + unrolled_ast: df68b369524adf6417661b438beafdfe21fbe3b2cd8b466cf8d256055cb13a90 + ssa_ast: d30cc1abaef24cb604cd7326a20576fbe814056baebf0d9d8a85c5474eabf786 + flattened_ast: e146e97ec34e52c785a58b59c8c792c9c69cdceda0c42e04b5dcd81f1014427b + inlined_ast: e146e97ec34e52c785a58b59c8c792c9c69cdceda0c42e04b5dcd81f1014427b dce_ast: 04c9e598ed205c643415ee43c445b30b6c6006e68eebb3dd6466e0e4ffb32a8a bytecode: aec6ee0fcfa292c5e3a4b9165408e9627b7c73b520302dc986293cc36fea4383 warnings: "" diff --git a/tests/expectations/compiler/integers/u64/operator_methods.out b/tests/expectations/compiler/integers/u64/operator_methods.out index 99b1d7e1ff..24b29dad8d 100644 --- a/tests/expectations/compiler/integers/u64/operator_methods.out +++ b/tests/expectations/compiler/integers/u64/operator_methods.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 65c6030ba915545327bfe7cdcdca627aa4682ee2cf90d94fb02690994523b08f - unrolled_ast: 65c6030ba915545327bfe7cdcdca627aa4682ee2cf90d94fb02690994523b08f - ssa_ast: 61f1e1380cc21c57ef71044e708ad8bc66cd1716dd137f15b589d3a145f54d5c - flattened_ast: 267033e0527434ffdfaeb8e6925490f3167499efc4dd8438c21dcbb4c6d66368 - inlined_ast: 267033e0527434ffdfaeb8e6925490f3167499efc4dd8438c21dcbb4c6d66368 + - - initial_ast: 280645f364bd8aa4bd4f604da1f18c0bc7fafe7dda71b7ee6d8f41dbc69ea723 + unrolled_ast: 280645f364bd8aa4bd4f604da1f18c0bc7fafe7dda71b7ee6d8f41dbc69ea723 + ssa_ast: 0a7397fbb66d0e2b509a3377e47ffe4b442aa29110713351ea6389358fa33e70 + flattened_ast: e128976b39d216eda2b4bd0d3ded7b7aeeca167ba59ffc0c7e766da6e01f558b + inlined_ast: e128976b39d216eda2b4bd0d3ded7b7aeeca167ba59ffc0c7e766da6e01f558b dce_ast: 1ea4de103bc144219a92332482fb7f957e5cef01ff092624acfbd8c017aff103 bytecode: e5ef9b94c6b2173341804d3fd3d6ca89bcdebc38ed22f7444bb4e140d86f5f00 warnings: "" diff --git a/tests/expectations/compiler/integers/u8/operator_methods.out b/tests/expectations/compiler/integers/u8/operator_methods.out index 6bb488aa0b..3390f4a648 100644 --- a/tests/expectations/compiler/integers/u8/operator_methods.out +++ b/tests/expectations/compiler/integers/u8/operator_methods.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 1f718cbf12cf368295b0cd0181e429f6d95565a13a13f148aa6593622e7f0c94 - unrolled_ast: 1f718cbf12cf368295b0cd0181e429f6d95565a13a13f148aa6593622e7f0c94 - ssa_ast: 5ebc40518c5fa13c810f4a30528552720e2fde023f2685a7c71bbace0c2d06b2 - flattened_ast: fb9676ebfc259e6d7925fe4cf2b55e99e47ab6c208eeb7256c741b25eda962ad - inlined_ast: fb9676ebfc259e6d7925fe4cf2b55e99e47ab6c208eeb7256c741b25eda962ad + - - initial_ast: f5bf22812daa18f683853c4af13f873d158cb825f2835e44b20b9bd68fb92ada + unrolled_ast: f5bf22812daa18f683853c4af13f873d158cb825f2835e44b20b9bd68fb92ada + ssa_ast: 8220d58dc8d62fbd22f19f4c5216c49371f5dc03ac2f7c4e83600cd7a55a1f55 + flattened_ast: 52b5a8d832d54d987d09e95da1255cf18f87f1bdc7e27713242e88d6eef90982 + inlined_ast: 52b5a8d832d54d987d09e95da1255cf18f87f1bdc7e27713242e88d6eef90982 dce_ast: b2be496652e117727901115cee8f73b222669dfd65792d02384bbd4dd6eaaa2b bytecode: 525aa7ee628bc18ddc77b4d2c0f21cc66858ecbdd517233862c7ba491158c69f warnings: "" diff --git a/tests/expectations/execution/cast_coersion.out b/tests/expectations/execution/cast_coersion.out new file mode 100644 index 0000000000..d454d04dff --- /dev/null +++ b/tests/expectations/execution/cast_coersion.out @@ -0,0 +1,22 @@ +--- +namespace: Execute +expectation: Pass +outputs: + - - initial_ast: afe29d66a28151220f870b3a7f8a78543ebfc6427adf4eb5950b1bd574b02a9e + unrolled_ast: afe29d66a28151220f870b3a7f8a78543ebfc6427adf4eb5950b1bd574b02a9e + ssa_ast: 45a2cf824da09572b0958ad5ec799d80fe6192a441eefa9cb021f11c519f8585 + flattened_ast: 3426de3487eefb807450d2bbf9e21cc8530bc9b82e38c93758e889179ba4cad5 + inlined_ast: 3426de3487eefb807450d2bbf9e21cc8530bc9b82e38c93758e889179ba4cad5 + dce_ast: 3426de3487eefb807450d2bbf9e21cc8530bc9b82e38c93758e889179ba4cad5 + bytecode: 675912267b82b91bd854fa2ef169b85c74ecaac6b73a157d7e99818e256b53b1 + warnings: "" + results: + main: + - input: "[true, 0group, aleo1x2mh70hxp6hejyrcuhd9te5ddwvwx6papw4tfpdxp00e4sf0ps9qcu8qvn]" + output: "[{\n data: 0field\n}, {\n data: 1field\n}]" + - input: "[false, 0group, aleo1x2mh70hxp6hejyrcuhd9te5ddwvwx6papw4tfpdxp00e4sf0ps9qcu8qvn]" + output: "[{\n data: 0field\n}, {\n data: 4544660252267858929884024594357493723883870730820258372918540470346309416754field\n}]" + - input: "[true, 2group, aleo1yrmttyqs4gtm8t6dtcg2vd2mtr8p6ukmpe42cp2zm0989rmtr58q0asawh]" + output: "[{\n data: 2field\n}, {\n data: 1field\n}]" + - input: "[false, 2group, aleo1yrmttyqs4gtm8t6dtcg2vd2mtr8p6ukmpe42cp2zm0989rmtr58q0asawh]" + output: "[{\n data: 2field\n}, {\n data: 6384360799264834139870961120883187693878405876485508427694934683059829995040field\n}]" diff --git a/tests/expectations/execution/primitive_casts.out b/tests/expectations/execution/primitive_casts.out new file mode 100644 index 0000000000..aa2550836e --- /dev/null +++ b/tests/expectations/execution/primitive_casts.out @@ -0,0 +1,58 @@ +--- +namespace: Execute +expectation: Pass +outputs: + - - initial_ast: 87083acc724b6b45386d91cb40437468e9362d3d5b787c6cc00c9507d48b6fe7 + unrolled_ast: 87083acc724b6b45386d91cb40437468e9362d3d5b787c6cc00c9507d48b6fe7 + ssa_ast: b1543138bf058637bb11c824adb10272fcfc4d80de634602b268f9532db1b4dd + flattened_ast: ed75543797b289033be1d4fd7b5c0b14ac6c77914bee927ef53a99cb96c4561c + inlined_ast: ed75543797b289033be1d4fd7b5c0b14ac6c77914bee927ef53a99cb96c4561c + dce_ast: ed75543797b289033be1d4fd7b5c0b14ac6c77914bee927ef53a99cb96c4561c + bytecode: 9f8baa3f1bada186c32440e4880e858bd76b54dedb2d667a2b93c2d2a98f0752 + warnings: "" + results: + address_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + bool_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + field_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + group_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + i128_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + i16_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + i32_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + i64_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + i8_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + scalar_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + u128_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + u16_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + u32_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + u64_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) + u8_casts: + - input: "[aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey, false, 0field, 0group, 0i8, 0i16, 0i32, 0i64, 0i128, 0u8, 0u16, 0u32, 0u64, 0u128, 0scalar]" + output: SnarkVMError(Cannot downcast a field literal to a boolean type (yet).) diff --git a/tests/expectations/parser/expression/binary/pow.out b/tests/expectations/parser/expression/binary/pow.out index 3518b91ced..b2274c57b6 100644 --- a/tests/expectations/parser/expression/binary/pow.out +++ b/tests/expectations/parser/expression/binary/pow.out @@ -46,16 +46,16 @@ outputs: hi: 8 - Binary: left: - Literal: - Integer: - - U8 - - "1" - - span: - lo: 0 - hi: 3 - right: Binary: left: + Literal: + Integer: + - U8 + - "1" + - span: + lo: 0 + hi: 3 + right: Literal: Integer: - U8 @@ -63,18 +63,18 @@ outputs: - span: lo: 7 hi: 10 - right: - Literal: - Integer: - - U8 - - "3" - - span: - lo: 14 - hi: 17 op: Pow span: - lo: 7 - hi: 17 + lo: 0 + hi: 10 + right: + Literal: + Integer: + - U8 + - "3" + - span: + lo: 14 + hi: 17 op: Pow span: lo: 0 diff --git a/tests/expectations/parser/expression/cast.out b/tests/expectations/parser/expression/cast.out new file mode 100644 index 0000000000..a4b0796634 --- /dev/null +++ b/tests/expectations/parser/expression/cast.out @@ -0,0 +1,123 @@ +--- +namespace: ParseExpression +expectation: Pass +outputs: + - Cast: + expression: + Identifier: "{\"name\":\"foo\",\"span\":\"{\\\"lo\\\":0,\\\"hi\\\":3}\"}" + type_: + Integer: U8 + span: + lo: 0 + hi: 9 + - Cast: + expression: + Literal: + Integer: + - U128 + - "1" + - span: + lo: 0 + hi: 5 + type_: + Integer: I8 + span: + lo: 0 + hi: 11 + - Cast: + expression: + Struct: + name: "{\"name\":\"baz\",\"span\":\"{\\\"lo\\\":0,\\\"hi\\\":3}\"}" + members: + - identifier: "{\"name\":\"foo\",\"span\":\"{\\\"lo\\\":6,\\\"hi\\\":9}\"}" + expression: + Identifier: "{\"name\":\"u8\",\"span\":\"{\\\"lo\\\":11,\\\"hi\\\":13}\"}" + span: + lo: 0 + hi: 15 + type_: Scalar + span: + lo: 0 + hi: 25 + - Ternary: + condition: + Identifier: "{\"name\":\"flag\",\"span\":\"{\\\"lo\\\":0,\\\"hi\\\":4}\"}" + if_true: + Literal: + Integer: + - U8 + - "1" + - span: + lo: 7 + hi: 10 + if_false: + Cast: + expression: + Literal: + Integer: + - U8 + - "0" + - span: + lo: 13 + hi: 16 + type_: Scalar + span: + lo: 13 + hi: 26 + span: + lo: 0 + hi: 26 + - Cast: + expression: + Ternary: + condition: + Identifier: "{\"name\":\"flag\",\"span\":\"{\\\"lo\\\":1,\\\"hi\\\":5}\"}" + if_true: + Literal: + Integer: + - U8 + - "1" + - span: + lo: 8 + hi: 11 + if_false: + Literal: + Integer: + - U8 + - "0" + - span: + lo: 14 + hi: 17 + span: + lo: 1 + hi: 17 + type_: Scalar + span: + lo: 1 + hi: 28 + - Cast: + expression: + Literal: + Integer: + - I8 + - "34" + - span: + lo: 0 + hi: 4 + type_: Field + span: + lo: 0 + hi: 13 + - Cast: + expression: + Literal: + Field: + - "0925348043850" + - span: + lo: 0 + hi: 18 + type_: + Integer: I8 + span: + lo: 0 + hi: 24 diff --git a/tests/expectations/parser/expression/cast_fail.out b/tests/expectations/parser/expression/cast_fail.out new file mode 100644 index 0000000000..c81c5f8f6b --- /dev/null +++ b/tests/expectations/parser/expression/cast_fail.out @@ -0,0 +1,9 @@ +--- +namespace: ParseExpression +expectation: Fail +outputs: + - "did not consume all input: 'aas' @ 1:5-8\n'u8' @ 1:9-11\n" + - "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- found '{'\n --> test:1:10\n |\n 1 | 1u128 as { foo: u8 }\n | ^" + - "did not consume all input: ';' @ 1:14-15\n" + - "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- found 'bar'\n --> test:1:8\n |\n 1 | 1u8 as bar;\n | ^^^" + - "did not consume all input: 'asu8' @ 1:5-9\n" diff --git a/tests/expectations/parser/unreachable/define.out b/tests/expectations/parser/unreachable/define.out index c9db5def6b..b4ffe3f7e0 100644 --- a/tests/expectations/parser/unreachable/define.out +++ b/tests/expectations/parser/unreachable/define.out @@ -25,7 +25,7 @@ outputs: - "Error [EPAR0370009]: unexpected string: expected 'expression', found '<='\n --> test:1:1\n |\n 1 | <= x = 10u8;\n | ^^" - "Error [EPAR0370009]: unexpected string: expected 'expression', found '>'\n --> test:1:1\n |\n 1 | > x = 10u8;\n | ^" - "Error [EPAR0370009]: unexpected string: expected 'expression', found '..'\n --> test:1:1\n |\n 1 | .. x = 10u8;\n | ^^" - - "Error [EPAR0370005]: expected ; -- found 'x'\n --> test:1:4\n |\n 1 | as x = 10u8;\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found 'as'\n --> test:1:1\n |\n 1 | as x = 10u8;\n | ^^" - "Error [EPAR0370032]: `console` statements are not yet supported.\n --> test:1:1\n |\n 1 | console x = 10u8;\n | ^^^^^^^\n |\n = Consider using `assert`, `assert_eq`, or `assert_neq` instead." - "Error [EPAR0370005]: expected : -- found '='\n --> test:1:7\n |\n 1 | for x = 10u8;\n | ^" - "Error [EPAR0370005]: expected { -- found '='\n --> test:1:6\n |\n 1 | if x = 10u8;\n | ^" diff --git a/tests/expectations/parser/unreachable/expect_ident.out b/tests/expectations/parser/unreachable/expect_ident.out index f14f2acbe1..0a5266ff93 100644 --- a/tests/expectations/parser/unreachable/expect_ident.out +++ b/tests/expectations/parser/unreachable/expect_ident.out @@ -30,7 +30,7 @@ outputs: - "Error [EPAR0370009]: unexpected string: expected 'identifier', found '<='\n --> test:1:4\n |\n 1 | x::<=\n | ^^" - "Error [EPAR0370009]: unexpected string: expected 'identifier', found '>'\n --> test:1:4\n |\n 1 | x::>\n | ^" - "Error [EPAR0370009]: unexpected string: expected 'identifier', found '..'\n --> test:1:4\n |\n 1 | x::..\n | ^^" - - "Error [EPAR0370005]: expected ; -- found ''\n --> test:1:4\n |\n 1 | x::as\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'identifier', found 'as'\n --> test:1:4\n |\n 1 | x::as\n | ^^" - "Error [EPAR0370009]: unexpected string: expected 'identifier', found 'console'\n --> test:1:4\n |\n 1 | x::console\n | ^^^^^^^" - "Error [EPAR0370005]: expected ; -- found ''\n --> test:1:4\n |\n 1 | x::const\n | ^^^^^" - "Error [EPAR0370009]: unexpected string: expected 'identifier', found 'let'\n --> test:1:4\n |\n 1 | x::let\n | ^^^" diff --git a/tests/tests/compiler/core/algorithms/bhp1024_commit_to_group.leo b/tests/tests/compiler/core/algorithms/bhp1024_commit_to_group.leo index b0ee269299..e9ea85b06f 100644 --- a/tests/tests/compiler/core/algorithms/bhp1024_commit_to_group.leo +++ b/tests/tests/compiler/core/algorithms/bhp1024_commit_to_group.leo @@ -22,7 +22,7 @@ program test.aleo { let addr_value: address = aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta; let bool_value: bool = true; let field_value: field = 1field; -// let group_value: group = group::GEN; + let group_value: group = group::GEN; let i128_value: i128 = 1i128; let u128_value: u128 = 1u128; let scalar_value: scalar = 1scalar; @@ -32,7 +32,7 @@ program test.aleo { let a: group = BHP1024::commit_to_group(addr_value, 1scalar); let b: group = BHP1024::commit_to_group(bool_value, 1scalar); let c: group = BHP1024::commit_to_group(field_value, 1scalar); -// let d: group = BHP1024::commit_to_field(group_value, 1scalar); + let d: group = BHP1024::commit_to_group(group_value, 1scalar); let e: group = BHP1024::commit_to_group(i8_value, 1scalar); let f: group = BHP1024::commit_to_group(i16_value, 1scalar); let g: group = BHP1024::commit_to_group(i32_value, 1scalar); diff --git a/tests/tests/compiler/core/algorithms/bhp256_commit_to_group.leo b/tests/tests/compiler/core/algorithms/bhp256_commit_to_group.leo index 10e69949dc..2e76deb9ad 100644 --- a/tests/tests/compiler/core/algorithms/bhp256_commit_to_group.leo +++ b/tests/tests/compiler/core/algorithms/bhp256_commit_to_group.leo @@ -22,7 +22,7 @@ program test.aleo { let addr_value: address = aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta; let bool_value: bool = true; let field_value: field = 1field; -// let group_value: group = group::GEN; + let group_value: group = group::GEN; let i128_value: i128 = 1i128; let u128_value: u128 = 1u128; let scalar_value: scalar = 1scalar; @@ -32,7 +32,7 @@ program test.aleo { let a: group = BHP256::commit_to_group(addr_value, 1scalar); let b: group = BHP256::commit_to_group(bool_value, 1scalar); let c: group = BHP256::commit_to_group(field_value, 1scalar); -// let d: group = BHP256::commit_to_group(group_value, 1scalar); + let d: group = BHP256::commit_to_group(group_value, 1scalar); let e: group = BHP256::commit_to_group(i8_value, 1scalar); let f: group = BHP256::commit_to_group(i16_value, 1scalar); let g: group = BHP256::commit_to_group(i32_value, 1scalar); diff --git a/tests/tests/compiler/core/algorithms/bhp512_commit_to_group.leo b/tests/tests/compiler/core/algorithms/bhp512_commit_to_group.leo index 1c12d7039e..7cdd0b135e 100644 --- a/tests/tests/compiler/core/algorithms/bhp512_commit_to_group.leo +++ b/tests/tests/compiler/core/algorithms/bhp512_commit_to_group.leo @@ -22,7 +22,7 @@ program test.aleo { let addr_value: address = aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta; let bool_value: bool = true; let field_value: field = 1field; -// let group_value: group = group::GEN; + let group_value: group = group::GEN; let i128_value: i128 = 1i128; let u128_value: u128 = 1u128; let scalar_value: scalar = 1scalar; @@ -32,7 +32,7 @@ program test.aleo { let a: group = BHP512::commit_to_group(addr_value, 1scalar); let b: group = BHP512::commit_to_group(bool_value, 1scalar); let c: group = BHP512::commit_to_group(field_value, 1scalar); -// let d: group = BHP512::commit_to_group(group_value, 1scalar); + let d: group = BHP512::commit_to_group(group_value, 1scalar); let e: group = BHP512::commit_to_group(i8_value, 1scalar); let f: group = BHP512::commit_to_group(i16_value, 1scalar); let g: group = BHP512::commit_to_group(i32_value, 1scalar); diff --git a/tests/tests/compiler/core/algorithms/bhp768_commit_to_group.leo b/tests/tests/compiler/core/algorithms/bhp768_commit_to_group.leo index 220294eb82..c6d451d713 100644 --- a/tests/tests/compiler/core/algorithms/bhp768_commit_to_group.leo +++ b/tests/tests/compiler/core/algorithms/bhp768_commit_to_group.leo @@ -22,7 +22,7 @@ program test.aleo { let addr_value: address = aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta; let bool_value: bool = true; let field_value: field = 1field; -// let group_value: group = group::GEN; + let group_value: group = group::GEN; let i128_value: i128 = 1i128; let u128_value: u128 = 1u128; let scalar_value: scalar = 1scalar; @@ -32,7 +32,7 @@ program test.aleo { let a: group = BHP768::commit_to_group(addr_value, 1scalar); let b: group = BHP768::commit_to_group(bool_value, 1scalar); let c: group = BHP768::commit_to_group(field_value, 1scalar); -// let d: group = BHP768::commit_to_field(group_value, 1scalar); + let d: group = BHP768::commit_to_group(group_value, 1scalar); let e: group = BHP768::commit_to_group(i8_value, 1scalar); let f: group = BHP768::commit_to_group(i16_value, 1scalar); let g: group = BHP768::commit_to_group(i32_value, 1scalar); diff --git a/tests/tests/compiler/expression/cast.leo b/tests/tests/compiler/expression/cast.leo new file mode 100644 index 0000000000..2e08725ee8 --- /dev/null +++ b/tests/tests/compiler/expression/cast.leo @@ -0,0 +1,205 @@ +/* +namespace: Compile +expectation: Pass +*/ + +program test.aleo { + // The primitive types are: `address`, `bool`, `field`, `group`, `i8`, `i16`, `i32`, `i64`, `i128`, `u8`, `u16`, `u32`, `u64`, `u128`, `scalar`. + // We can cast between all of these types. + transition main(a: address, b: bool, c: field, d: i8, e: i16, f: i64, g: i128, h: u8, i: u16, j: u32, k: u64, l: u128, m: scalar) -> bool { + let a_field: field = a as field; + let a_group: group = a as group; + let a_bool: bool = a as bool; + let a_i8: i8 = a as i8; + let a_i16: i16 = a as i16; + let a_i32: i32 = a as i32; + let a_i64: i64 = a as i64; + let a_i128: i128 = a as i128; + let a_u8: u8 = a as u8; + let a_u16: u16 = a as u16; + let a_u32: u32 = a as u32; + let a_u64: u64 = a as u64; + let a_u128: u128 = a as u128; + let a_scalar: scalar = a as scalar; + + let b_field: field = b as field; + let b_group: group = b as group; + let b_bool: bool = b as bool; + let b_i8: i8 = b as i8; + let b_i16: i16 = b as i16; + let b_i32: i32 = b as i32; + let b_i64: i64 = b as i64; + let b_i128: i128 = b as i128; + let b_u8: u8 = b as u8; + let b_u16: u16 = b as u16; + let b_u32: u32 = b as u32; + let b_u64: u64 = b as u64; + let b_u128: u128 = b as u128; + let b_scalar: scalar = b as scalar; + + let c_field: field = c as field; + let c_group: group = c as group; + let c_bool: bool = c as bool; + let c_i8: i8 = c as i8; + let c_i16: i16 = c as i16; + let c_i32: i32 = c as i32; + let c_i64: i64 = c as i64; + let c_i128: i128 = c as i128; + let c_u8: u8 = c as u8; + let c_u16: u16 = c as u16; + let c_u32: u32 = c as u32; + let c_u64: u64 = c as u64; + let c_u128: u128 = c as u128; + let c_scalar: scalar = c as scalar; + + let d_field: field = d as field; + let d_group: group = d as group; + let d_bool: bool = d as bool; + let d_i8: i8 = d as i8; + let d_i16: i16 = d as i16; + let d_i32: i32 = d as i32; + let d_i64: i64 = d as i64; + let d_i128: i128 = d as i128; + let d_u8: u8 = d as u8; + let d_u16: u16 = d as u16; + let d_u32: u32 = d as u32; + let d_u64: u64 = d as u64; + let d_u128: u128 = d as u128; + let d_scalar: scalar = d as scalar; + + let e_field: field = e as field; + let e_group: group = e as group; + let e_bool: bool = e as bool; + let e_i8: i8 = e as i8; + let e_i16: i16 = e as i16; + let e_i32: i32 = e as i32; + let e_i64: i64 = e as i64; + let e_i128: i128 = e as i128; + let e_u8: u8 = e as u8; + let e_u16: u16 = e as u16; + let e_u32: u32 = e as u32; + let e_u64: u64 = e as u64; + let e_u128: u128 = e as u128; + let e_scalar: scalar = e as scalar; + + let f_field: field = f as field; + let f_group: group = f as group; + let f_bool: bool = f as bool; + let f_i8: i8 = f as i8; + let f_i16: i16 = f as i16; + let f_i32: i32 = f as i32; + let f_i64: i64 = f as i64; + let f_i128: i128 = f as i128; + let f_u8: u8 = f as u8; + let f_u16: u16 = f as u16; + let f_u32: u32 = f as u32; + let f_u64: u64 = f as u64; + let f_u128: u128 = f as u128; + let f_scalar: scalar = f as scalar; + + let g_field: field = g as field; + let g_group: group = g as group; + let g_bool: bool = g as bool; + let g_i8: i8 = g as i8; + let g_i16: i16 = g as i16; + let g_i32: i32 = g as i32; + let g_i64: i64 = g as i64; + let g_i128: i128 = g as i128; + let g_u8: u8 = g as u8; + let g_u16: u16 = g as u16; + let g_u32: u32 = g as u32; + let g_u64: u64 = g as u64; + let g_u128: u128 = g as u128; + let g_scalar: scalar = g as scalar; + + let h_field: field = h as field; + let h_group: group = h as group; + let h_bool: bool = h as bool; + let h_i8: i8 = h as i8; + let h_i16: i16 = h as i16; + let h_i32: i32 = h as i32; + let h_i64: i64 = h as i64; + let h_i128: i128 = h as i128; + let h_u8: u8 = h as u8; + let h_u16: u16 = h as u16; + let h_u32: u32 = h as u32; + let h_u64: u64 = h as u64; + let h_u128: u128 = h as u128; + let h_scalar: scalar = h as scalar; + + let i_field: field = i as field; + let i_group: group = i as group; + let i_bool: bool = i as bool; + let i_i8: i8 = i as i8; + let i_i16: i16 = i as i16; + let i_i32: i32 = i as i32; + let i_i64: i64 = i as i64; + let i_i128: i128 = i as i128; + let i_u8: u8 = i as u8; + let i_u16: u16 = i as u16; + let i_u32: u32 = i as u32; + let i_u64: u64 = i as u64; + let i_u128: u128 = i as u128; + let i_scalar: scalar = i as scalar; + + let j_field: field = j as field; + let j_group: group = j as group; + let j_bool: bool = j as bool; + let j_i8: i8 = j as i8; + let j_i16: i16 = j as i16; + let j_i32: i32 = j as i32; + let j_i64: i64 = j as i64; + let j_i128: i128 = j as i128; + let j_u8: u8 = j as u8; + let j_u16: u16 = j as u16; + let j_u32: u32 = j as u32; + let j_u64: u64 = j as u64; + let j_u128: u128 = j as u128; + let j_scalar: scalar = j as scalar; + + let k_field: field = k as field; + let k_group: group = k as group; + let k_bool: bool = k as bool; + let k_i8: i8 = k as i8; + let k_i16: i16 = k as i16; + let k_i32: i32 = k as i32; + let k_i64: i64 = k as i64; + let k_i128: i128 = k as i128; + let k_u8: u8 = k as u8; + let k_u16: u16 = k as u16; + let k_u32: u32 = k as u32; + let k_u64: u64 = k as u64; + let k_u128: u128 = k as u128; + + let l_field: field = l as field; + let l_group: group = l as group; + let l_bool: bool = l as bool; + let l_i8: i8 = l as i8; + let l_i16: i16 = l as i16; + let l_i32: i32 = l as i32; + let l_i64: i64 = l as i64; + let l_i128: i128 = l as i128; + let l_u8: u8 = l as u8; + let l_u16: u16 = l as u16; + let l_u32: u32 = l as u32; + let l_u64: u64 = l as u64; + let l_u128: u128 = l as u128; + let l_scalar: scalar = l as scalar; + + let m_field: field = m as field; + let m_group: group = m as group; + let m_bool: bool = m as bool; + let m_i8: i8 = m as i8; + let m_i16: i16 = m as i16; + let m_i32: i32 = m as i32; + let m_i64: i64 = m as i64; + let m_i128: i128 = m as i128; + let m_u8: u8 = m as u8; + let m_u16: u16 = m as u16; + let m_u32: u32 = m as u32; + let m_u64: u64 = m as u64; + let m_u128: u128 = m as u128; + + return l_field == m_field; + } +} diff --git a/tests/tests/compiler/expression/cast_coersion.leo b/tests/tests/compiler/expression/cast_coersion.leo new file mode 100644 index 0000000000..ab135a5cd2 --- /dev/null +++ b/tests/tests/compiler/expression/cast_coersion.leo @@ -0,0 +1,22 @@ +/* +namespace: Compile +expectation: Pass +*/ + +program test.aleo { + + struct foo { + data: field, + } + + transition main(f: bool, a: group, b: address) -> (foo, foo) { + let first: foo = foo { data: a as field }; + if f { + let second: foo = foo { data: 1field }; + return (first, second); + } else { + let second: foo = foo { data: b as field }; + return (first, second); + } + } +} diff --git a/tests/tests/compiler/expression/cast_fail.leo b/tests/tests/compiler/expression/cast_fail.leo new file mode 100644 index 0000000000..d70abbacdf --- /dev/null +++ b/tests/tests/compiler/expression/cast_fail.leo @@ -0,0 +1,31 @@ +/* +namespace: Compile +expectation: Fail +*/ + +program test.aleo { + + mapping balances: field => field; + + struct Foo { + data: field; + } + + transition main(a: field) { + // Cannot cast to a string. + let b: string = a as string; + // Cannot cast a struct. + let c: Foo = Foo { data: a }; + let d: field = c as field; + // Cannot cast a tuple. + let e: (field, field) = (a, a); + let f: field = e as field; + return then finalize(a); + } + + finalize main(a: field) { + // Cannot cast a mapping. + let b: field = balances as field; + assert_eq(b, a); + } +} diff --git a/tests/tests/compiler/integers/i128/operator_methods.leo b/tests/tests/compiler/integers/i128/operator_methods.leo index 0753d34dde..5cb659ce3c 100644 --- a/tests/tests/compiler/integers/i128/operator_methods.leo +++ b/tests/tests/compiler/integers/i128/operator_methods.leo @@ -45,8 +45,8 @@ program test.aleo { let ap: i128 = a.shr_wrapped(2u16); let aq: i128 = a.shr_wrapped(2u32); let ar: i128 = a.xor(b); - let as: i128 = a.rem(b); - let at: i128 = a.rem_wrapped(b); + let at: i128 = a.rem(b); + let au: i128 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/i16/operator_methods.leo b/tests/tests/compiler/integers/i16/operator_methods.leo index 21f9d09c93..99048b5da7 100644 --- a/tests/tests/compiler/integers/i16/operator_methods.leo +++ b/tests/tests/compiler/integers/i16/operator_methods.leo @@ -45,8 +45,8 @@ program test.aleo { let ap: i16 = a.shr_wrapped(2u16); let aq: i16 = a.shr_wrapped(2u32); let ar: i16 = a.xor(b); - let as: i16 = a.rem(b); - let at: i16 = a.rem_wrapped(b); + let at: i16 = a.rem(b); + let au: i16 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/i32/operator_methods.leo b/tests/tests/compiler/integers/i32/operator_methods.leo index e9a81e2118..61a4bb456c 100644 --- a/tests/tests/compiler/integers/i32/operator_methods.leo +++ b/tests/tests/compiler/integers/i32/operator_methods.leo @@ -45,8 +45,8 @@ program test.aleo { let ap: i32 = a.shr_wrapped(2u16); let aq: i32 = a.shr_wrapped(2u32); let ar: i32 = a.xor(b); - let as: i32 = a.rem(b); - let at: i32 = a.rem_wrapped(b); + let at: i32 = a.rem(b); + let au: i32 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/i64/operator_methods.leo b/tests/tests/compiler/integers/i64/operator_methods.leo index f7ee0f1419..342a00805d 100644 --- a/tests/tests/compiler/integers/i64/operator_methods.leo +++ b/tests/tests/compiler/integers/i64/operator_methods.leo @@ -45,8 +45,8 @@ program test.aleo { let ap: i64 = a.shr_wrapped(2u16); let aq: i64 = a.shr_wrapped(2u32); let ar: i64 = a.xor(b); - let as: i64 = a.rem(b); - let at: i64 = a.rem_wrapped(b); + let at: i64 = a.rem(b); + let au: i64 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/i8/operator_methods.leo b/tests/tests/compiler/integers/i8/operator_methods.leo index 37ec2f0ed5..5f35349478 100644 --- a/tests/tests/compiler/integers/i8/operator_methods.leo +++ b/tests/tests/compiler/integers/i8/operator_methods.leo @@ -45,8 +45,8 @@ program test.aleo { let ap: i8 = a.shr_wrapped(2u16); let aq: i8 = a.shr_wrapped(2u32); let ar: i8 = a.xor(b); - let as: i8 = a.rem(b); - let at: i8 = a.rem_wrapped(b); + let at: i8 = a.rem(b); + let au: i8 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/u128/operator_methods.leo b/tests/tests/compiler/integers/u128/operator_methods.leo index cad091b769..eb703c47a3 100644 --- a/tests/tests/compiler/integers/u128/operator_methods.leo +++ b/tests/tests/compiler/integers/u128/operator_methods.leo @@ -42,9 +42,9 @@ program test.aleo { let ap: u128 = a.shr_wrapped(2u16); let aq: u128 = a.shr_wrapped(2u32); let ar: u128 = a.xor(b); - let as: u128 = a.mod(b); - let at: u128 = a.rem(b); - let au: u128 = a.rem_wrapped(b); + let at: u128 = a.mod(b); + let au: u128 = a.rem(b); + let av: u128 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/u16/operator_methods.leo b/tests/tests/compiler/integers/u16/operator_methods.leo index d02892108c..796ca1edc5 100644 --- a/tests/tests/compiler/integers/u16/operator_methods.leo +++ b/tests/tests/compiler/integers/u16/operator_methods.leo @@ -43,9 +43,9 @@ program test.aleo { let ap: u16 = a.shr_wrapped(b); let aq: u16 = a.shr_wrapped(2u32); let ar: u16 = a.xor(b); - let as: u16 = a.mod(b); - let at: u16 = a.rem(b); - let au: u16 = a.rem_wrapped(b); + let at: u16 = a.mod(b); + let au: u16 = a.rem(b); + let av: u16 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/u32/operator_methods.leo b/tests/tests/compiler/integers/u32/operator_methods.leo index 28144b7af9..a290585b69 100644 --- a/tests/tests/compiler/integers/u32/operator_methods.leo +++ b/tests/tests/compiler/integers/u32/operator_methods.leo @@ -43,9 +43,9 @@ program test.aleo { let ap: u32 = a.shr_wrapped(2u16); let aq: u32 = a.shr_wrapped(b); let ar: u32 = a.xor(b); - let as: u32 = a.mod(b); - let at: u32 = a.rem(b); - let au: u32 = a.rem_wrapped(b); + let at: u32 = a.mod(b); + let au: u32 = a.rem(b); + let av: u32 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/u64/operator_methods.leo b/tests/tests/compiler/integers/u64/operator_methods.leo index cd2afcf66f..5915d5aac5 100644 --- a/tests/tests/compiler/integers/u64/operator_methods.leo +++ b/tests/tests/compiler/integers/u64/operator_methods.leo @@ -42,9 +42,9 @@ program test.aleo { let ap: u64 = a.shr_wrapped(2u16); let aq: u64 = a.shr_wrapped(2u32); let ar: u64 = a.xor(b); - let as: u64 = a.mod(b); - let at: u64 = a.rem(b); - let au: u64 = a.rem_wrapped(b); + let at: u64 = a.mod(b); + let au: u64 = a.rem(b); + let av: u64 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/u8/operator_methods.leo b/tests/tests/compiler/integers/u8/operator_methods.leo index 84bf767816..a067b6487a 100644 --- a/tests/tests/compiler/integers/u8/operator_methods.leo +++ b/tests/tests/compiler/integers/u8/operator_methods.leo @@ -42,9 +42,9 @@ program test.aleo { let ap: u8 = a.shr_wrapped(2u16); let aq: u8 = a.shr_wrapped(2u32); let ar: u8 = a.xor(b); - let as: u8 = a.mod(b); - let at: u8 = a.rem(b); - let au: u8 = a.rem_wrapped(b); + let at: u8 = a.mod(b); + let au: u8 = a.rem(b); + let av: u8 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/execution/cast_coersion.leo b/tests/tests/execution/cast_coersion.leo new file mode 100644 index 0000000000..18efcdf583 --- /dev/null +++ b/tests/tests/execution/cast_coersion.leo @@ -0,0 +1,28 @@ +/* +namespace: Execute +expectation: Pass +cases: + main: + - input: ["true", "0group", "aleo1x2mh70hxp6hejyrcuhd9te5ddwvwx6papw4tfpdxp00e4sf0ps9qcu8qvn"] + - input: ["false", "0group", "aleo1x2mh70hxp6hejyrcuhd9te5ddwvwx6papw4tfpdxp00e4sf0ps9qcu8qvn"] + - input: ["true", "2group", "aleo1yrmttyqs4gtm8t6dtcg2vd2mtr8p6ukmpe42cp2zm0989rmtr58q0asawh"] + - input: ["false", "2group", "aleo1yrmttyqs4gtm8t6dtcg2vd2mtr8p6ukmpe42cp2zm0989rmtr58q0asawh"] +*/ + +program test.aleo { + + struct foo { + data: field, + } + + transition main(f: bool, a: group, b: address) -> (foo, foo) { + let first: foo = foo { data: a as field }; + if f { + let second: foo = foo { data: 1field }; + return (first, second); + } else { + let second: foo = foo { data: b as field }; + return (first, second); + } + } +} diff --git a/tests/tests/execution/primitive_casts.leo b/tests/tests/execution/primitive_casts.leo new file mode 100644 index 0000000000..fbc190e6a5 --- /dev/null +++ b/tests/tests/execution/primitive_casts.leo @@ -0,0 +1,104 @@ +/* +namespace: Execute +expectation: Pass +cases: + address_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + bool_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + field_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + group_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + i8_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + i16_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + i32_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + i64_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + i128_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + u8_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + u16_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + u32_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + u64_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + u128_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + scalar_casts: + - input: ["aleo1hjnn8jdxlzzlqjywamdx4hzcxny5gszzm0q5xmnae4ed6qqn2gys4ugtey", "false", "0field", "0group", "0i8", "0i16", "0i32", "0i64", "0i128", "0u8", "0u16", "0u32", "0u64", "0u128", "0scalar"] + + + +*/ + +program test.aleo { + transition address_casts(a: address) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (a as address, a as bool, a as field, a as group, a as i8, a as i16, a as i32, a as i64, a as i128, a as u8, a as u16, a as u32, a as u64, a as u128, a as scalar); + } + + transition bool_casts(b: bool) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (b as address, b as bool, b as field, b as group, b as i8, b as i16, b as i32, b as i64, b as i128, b as u8, b as u16, b as u32, b as u64, b as u128, b as scalar); + } + + transition field_casts(f: field) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (f as address, f as bool, f as field, f as group, f as i8, f as i16, f as i32, f as i64, f as i128, f as u8, f as u16, f as u32, f as u64, f as u128, f as scalar); + } + + transition group_casts(g: group) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (g as address, g as bool, g as field, g as group, g as i8, g as i16, g as i32, g as i64, g as i128, g as u8, g as u16, g as u32, g as u64, g as u128, g as scalar); + } + + transition i8_casts(i: i8) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (i as address, i as bool, i as field, i as group, i as i8, i as i16, i as i32, i as i64, i as i128, i as u8, i as u16, i as u32, i as u64, i as u128, i as scalar); + } + + transition i16_casts(i: i16) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (i as address, i as bool, i as field, i as group, i as i8, i as i16, i as i32, i as i64, i as i128, i as u8, i as u16, i as u32, i as u64, i as u128, i as scalar); + } + + transition i32_casts(i: i32) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (i as address, i as bool, i as field, i as group, i as i8, i as i16, i as i32, i as i64, i as i128, i as u8, i as u16, i as u32, i as u64, i as u128, i as scalar); + } + + transition i64_casts(i: i64) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (i as address, i as bool, i as field, i as group, i as i8, i as i16, i as i32, i as i64, i as i128, i as u8, i as u16, i as u32, i as u64, i as u128, i as scalar); + } + + transition i128_casts(i: i128) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (i as address, i as bool, i as field, i as group, i as i8, i as i16, i as i32, i as i64, i as i128, i as u8, i as u16, i as u32, i as u64, i as u128, i as scalar); + } + + transition u8_casts(u: u8) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (u as address, u as bool, u as field, u as group, u as i8, u as i16, u as i32, u as i64, u as i128, u as u8, u as u16, u as u32, u as u64, u as u128, u as scalar); + } + + transition u16_casts(u: u16) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (u as address, u as bool, u as field, u as group, u as i8, u as i16, u as i32, u as i64, u as i128, u as u8, u as u16, u as u32, u as u64, u as u128, u as scalar); + } + + transition u32_casts(u: u32) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (u as address, u as bool, u as field, u as group, u as i8, u as i16, u as i32, u as i64, u as i128, u as u8, u as u16, u as u32, u as u64, u as u128, u as scalar); + } + + transition u64_casts(u: u64) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (u as address, u as bool, u as field, u as group, u as i8, u as i16, u as i32, u as i64, u as i128, u as u8, u as u16, u as u32, u as u64, u as u128, u as scalar); + } + + transition u128_casts(u: u128) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (u as address, u as bool, u as field, u as group, u as i8, u as i16, u as i32, u as i64, u as i128, u as u8, u as u16, u as u32, u as u64, u as u128, u as scalar); + } + + transition scalar_casts(s: scalar) -> (address, bool, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar) { + return (s as address, s as bool, s as field, s as group, s as i8, s as i16, s as i32, s as i64, s as i128, s as u8, s as u16, s as u32, s as u64, s as u128, s as scalar); + } +} + + + + diff --git a/tests/tests/parser/expression/cast.leo b/tests/tests/parser/expression/cast.leo new file mode 100644 index 0000000000..e25255cf72 --- /dev/null +++ b/tests/tests/parser/expression/cast.leo @@ -0,0 +1,18 @@ +/* +namespace: ParseExpression +expectation: Pass +*/ + +foo as u8 + +1u128 as i8 + +baz { foo: u8 } as scalar + +flag ? 1u8 : 0u8 as scalar + +(flag ? 1u8 : 0u8) as scalar + +34i8 as field + +0925348043850field as i8 diff --git a/tests/tests/parser/expression/cast_fail.leo b/tests/tests/parser/expression/cast_fail.leo new file mode 100644 index 0000000000..a43b3c8e35 --- /dev/null +++ b/tests/tests/parser/expression/cast_fail.leo @@ -0,0 +1,14 @@ +/* +namespace: ParseExpression +expectation: Fail +*/ + +foo aas u8 + +1u128 as { foo: u8 } + +3i16 as field; + +1u8 as bar; + +f00 asu8