From c2bed2bb54dd27c418eff59e11e939107dfff39d Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Tue, 13 Sep 2022 11:06:24 +0200 Subject: [PATCH] Add name to finalize block --- compiler/ast/src/functions/finalize.rs | 19 +++++- compiler/ast/src/passes/reconstructor.rs | 1 + compiler/parser/src/parser/file.rs | 5 +- .../src/code_generation/visit_program.rs | 2 +- .../passes/src/flattening/flatten_program.rs | 1 + .../src/loop_unrolling/unroll_program.rs | 1 + .../rename_program.rs | 1 + .../passes/src/type_checking/check_program.rs | 10 ++++ .../errors/type_checker/type_checker_error.rs | 7 +++ examples/token/src/main.leo | 16 +++-- .../finalize/closure_with_finalize_fail.leo | 8 ++- tests/compiler/finalize/decrement.leo | 4 +- .../finalize/decrement_incorrect_type.leo | 4 +- .../compiler/finalize/empty_finalize_fail.leo | 4 +- tests/compiler/finalize/finalize.leo | 10 +++- .../finalize_incorrect_modes_fail.leo | 8 ++- .../finalize_incorrect_return_fail.leo | 4 +- .../finalize/finalize_missing_return_fail.leo | 4 +- .../finalize/finalize_name_mismatch_fail.leo | 17 ++++++ ...finalize_statement_incorrect_args_fail.leo | 4 +- ...nalize_without_finalize_statement_fail.leo | 4 +- tests/compiler/finalize/increment.leo | 4 +- .../finalize/increment_incorrect_type.leo | 4 +- .../finalize/read_write_mapping_fail.leo | 8 ++- tests/compiler/function/self.leo | 2 +- .../finalize/closure_with_finalize_fail.out | 2 +- .../compiler/finalize/decrement.out | 8 +-- .../finalize/decrement_incorrect_type.out | 2 +- .../compiler/finalize/empty_finalize_fail.out | 2 +- .../compiler/finalize/finalize.out | 8 +-- .../finalize_incorrect_modes_fail.out | 2 +- .../finalize_incorrect_return_fail.out | 2 +- .../finalize/finalize_missing_return_fail.out | 2 +- .../finalize/finalize_name_mismatch_fail.out | 5 ++ ...nalize_without_finalize_statement_fail.out | 2 +- .../compiler/finalize/increment.out | 8 +-- .../finalize/increment_incorrect_type.out | 2 +- tests/expectations/compiler/function/self.out | 8 +-- .../expectations/compiler/mapping/mapping.out | 10 ---- .../compiler/mapping/mapping_fail.out | 5 -- .../compiler/mapping/simple_mapping.out | 9 --- .../compiler/mapping/tuple_mapping_fail.out | 5 -- .../expectations/parser/finalize/finalize.out | 58 ++++++++++--------- .../parser/finalize/finalize_fail.out | 2 +- tests/parser/finalize/finalize.leo | 6 +- tests/parser/finalize/finalize_fail.leo | 8 ++- 46 files changed, 195 insertions(+), 113 deletions(-) create mode 100644 tests/compiler/finalize/finalize_name_mismatch_fail.leo create mode 100644 tests/expectations/compiler/finalize/finalize_name_mismatch_fail.out delete mode 100644 tests/expectations/compiler/mapping/mapping.out delete mode 100644 tests/expectations/compiler/mapping/mapping_fail.out delete mode 100644 tests/expectations/compiler/mapping/simple_mapping.out delete mode 100644 tests/expectations/compiler/mapping/tuple_mapping_fail.out diff --git a/compiler/ast/src/functions/finalize.rs b/compiler/ast/src/functions/finalize.rs index c4c4fa0e44..5eab12c658 100644 --- a/compiler/ast/src/functions/finalize.rs +++ b/compiler/ast/src/functions/finalize.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Block, FunctionInput, FunctionOutput, Node, Tuple, Type}; +use crate::{Block, FunctionInput, FunctionOutput, Identifier, Node, Tuple, Type}; use leo_span::Span; @@ -24,6 +24,8 @@ use serde::{Deserialize, Serialize}; /// A finalize block. #[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug)] pub struct Finalize { + /// The finalize identifier. + pub identifier: Identifier, /// The finalize block's input parameters. pub input: Vec, /// The finalize blocks's output declaration. @@ -38,7 +40,13 @@ pub struct Finalize { impl Finalize { /// Create a new finalize block. - pub fn new(input: Vec, output: Vec, block: Block, span: Span) -> Self { + pub fn new( + identifier: Identifier, + input: Vec, + output: Vec, + block: Block, + span: Span, + ) -> Self { let output_type = match output.len() { 0 => Type::Unit, 1 => output[0].type_.clone(), @@ -46,6 +54,7 @@ impl Finalize { }; Self { + identifier, input, output, output_type, @@ -66,7 +75,11 @@ impl fmt::Display for Finalize { self.output.iter().map(|x| x.to_string()).collect::>().join(",") ), }; - write!(f, " finalize({}) -> {} {}", parameters, returns, self.block) + write!( + f, + " finalize {}({}) -> {} {}", + self.identifier, parameters, returns, self.block + ) } } diff --git a/compiler/ast/src/passes/reconstructor.rs b/compiler/ast/src/passes/reconstructor.rs index c9ea8c1470..7600c29396 100644 --- a/compiler/ast/src/passes/reconstructor.rs +++ b/compiler/ast/src/passes/reconstructor.rs @@ -346,6 +346,7 @@ pub trait ProgramReconstructor: StatementReconstructor { output_type: input.output_type, block: self.reconstruct_block(input.block).0, finalize: input.finalize.map(|finalize| Finalize { + identifier: finalize.identifier, input: finalize.input, output: finalize.output, output_type: finalize.output_type, diff --git a/compiler/parser/src/parser/file.rs b/compiler/parser/src/parser/file.rs index edf2038b53..240bb59c9a 100644 --- a/compiler/parser/src/parser/file.rs +++ b/compiler/parser/src/parser/file.rs @@ -369,6 +369,9 @@ impl ParserContext<'_> { // Get starting span. let start = self.prev_token.span; + // Parse the identifier. + let identifier = self.expect_identifier()?; + // Parse parameters. let (input, ..) = self.parse_paren_comma_list(|p| p.parse_function_input().map(Some))?; @@ -390,7 +393,7 @@ impl ParserContext<'_> { let block = self.parse_block()?; let span = start + block.span; - Some(Finalize::new(input, output, block, span)) + Some(Finalize::new(identifier, input, output, block, span)) } }; diff --git a/compiler/passes/src/code_generation/visit_program.rs b/compiler/passes/src/code_generation/visit_program.rs index c4314ddfe2..37fc6950b6 100644 --- a/compiler/passes/src/code_generation/visit_program.rs +++ b/compiler/passes/src/code_generation/visit_program.rs @@ -212,7 +212,7 @@ impl<'a> CodeGenerator<'a> { self.variable_mapping = IndexMap::new(); self.variable_mapping.insert(&sym::SelfLower, "self".to_string()); - function_string.push_str(&format!("\nfinalize {}:\n", function.identifier)); + function_string.push_str(&format!("\nfinalize {}:\n", finalize.identifier)); // Construct and append the input declarations of the finalize block. for input in finalize.input.iter() { diff --git a/compiler/passes/src/flattening/flatten_program.rs b/compiler/passes/src/flattening/flatten_program.rs index a523c404ee..9764571db6 100644 --- a/compiler/passes/src/flattening/flatten_program.rs +++ b/compiler/passes/src/flattening/flatten_program.rs @@ -50,6 +50,7 @@ impl ProgramReconstructor for Flattener<'_> { self.finalizes = vec![vec![]; finalize.input.len()]; Finalize { + identifier: finalize.identifier, input: finalize.input, output: finalize.output, output_type: finalize.output_type, diff --git a/compiler/passes/src/loop_unrolling/unroll_program.rs b/compiler/passes/src/loop_unrolling/unroll_program.rs index 8779d0797f..f68390ec74 100644 --- a/compiler/passes/src/loop_unrolling/unroll_program.rs +++ b/compiler/passes/src/loop_unrolling/unroll_program.rs @@ -46,6 +46,7 @@ impl ProgramReconstructor for Unroller<'_> { self.exit_scope(previous_scope_index); Finalize { + identifier: finalize.identifier, input: finalize.input, output: finalize.output, output_type: finalize.output_type, diff --git a/compiler/passes/src/static_single_assignment/rename_program.rs b/compiler/passes/src/static_single_assignment/rename_program.rs index 5780448034..e3693166f6 100644 --- a/compiler/passes/src/static_single_assignment/rename_program.rs +++ b/compiler/passes/src/static_single_assignment/rename_program.rs @@ -61,6 +61,7 @@ impl FunctionConsumer for StaticSingleAssigner { self.pop(); Finalize { + identifier: finalize.identifier, input: finalize.input, output: finalize.output, output_type: finalize.output_type, diff --git a/compiler/passes/src/type_checking/check_program.rs b/compiler/passes/src/type_checking/check_program.rs index 20f997058e..773bc8adea 100644 --- a/compiler/passes/src/type_checking/check_program.rs +++ b/compiler/passes/src/type_checking/check_program.rs @@ -205,12 +205,22 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> { // The function;s finalize block does not have a finalize statement. self.has_finalize = false; + // Check that the function is a program function. if !self.is_program_function { self.emit_err(TypeCheckerError::only_program_functions_can_have_finalize( finalize.span, )); } + // Check that the name of the finalize block matches the function name. + if function.identifier.name != finalize.identifier.name { + self.emit_err(TypeCheckerError::finalize_name_mismatch( + function.identifier.name, + finalize.identifier.name, + finalize.span, + )); + } + // Create a new child scope for the finalize block. let scope_index = self.create_child_scope(); diff --git a/errors/src/errors/type_checker/type_checker_error.rs b/errors/src/errors/type_checker/type_checker_error.rs index 054e47d831..d0ff71d100 100644 --- a/errors/src/errors/type_checker/type_checker_error.rs +++ b/errors/src/errors/type_checker/type_checker_error.rs @@ -395,4 +395,11 @@ create_messages!( msg: format!("Function must contain a `finalize` statement on all execution paths."), help: None, } + + @formatted + finalize_name_mismatch { + args: (finalize_name: impl Display, function_name: impl Display), + msg: format!("`finalize` name `{finalize_name}` does not match function name `{function_name}`"), + help: None, + } ); diff --git a/examples/token/src/main.leo b/examples/token/src/main.leo index 120368c093..04b4efc823 100644 --- a/examples/token/src/main.leo +++ b/examples/token/src/main.leo @@ -18,7 +18,9 @@ record token { function mint_public(public receiver: address, public amount: u64) { // Mint the tokens publicly by invoking the computation on-chain. finalize(receiver, amount); -} finalize (public receiver: address, public amount: u64) { +} + +finalize mint_public(public receiver: address, public amount: u64) { // Increments `account[receiver]` by `amount`. // If `account[receiver]` does not exist, it will be created. // If `account[receiver] + amount` overflows, `mint_public` is reverted. @@ -40,7 +42,9 @@ function mint_private(receiver: address, amount: u64) -> token { function transfer_public(public receiver: address, public amount: u64) { // Transfer the tokens publicly, by invoking the computation on-chain. finalize(self.caller, receiver, amount); -} finalize (public sender: address, public receiver: address, public amount: u64) { +} + +finalize transfer_public(public sender: address, public receiver: address, public amount: u64) { // Decrements `account[sender]` by `amount`. // If `account[sender]` does not exist, it will be created. // If `account[sender] - amount` underflows, `transfer_public` is reverted. @@ -98,7 +102,9 @@ function transfer_private_to_public(sender: token, public receiver: address, pub // Output the sender's change record. return remaining; -} finalize (public receiver: address, public amount: u64) { +} + +finalize transfer_private_to_public(public receiver: address, public amount: u64) { // Increments `account[receiver]` by `amount`. // If `account[receiver]` does not exist, it will be created. // If `account[receiver] + amount` overflows, `transfer_private_to_public` is reverted. @@ -121,7 +127,9 @@ function transfer_public_to_private(public receiver: address, public amount: u64 // Output the receiver's record. return transferred; -} finalize (public sender: address, public amount: u64) { +} + +finalize transfer_public_to_private(public sender: address, public amount: u64) { // Decrements `account[sender]` by `amount`. // If `account[sender]` does not exist, it will be created. // If `account[sender] - amount` underflows, `transfer_public_to_private` is reverted. diff --git a/tests/compiler/finalize/closure_with_finalize_fail.leo b/tests/compiler/finalize/closure_with_finalize_fail.leo index 485a59d27b..0004d79fc2 100644 --- a/tests/compiler/finalize/closure_with_finalize_fail.leo +++ b/tests/compiler/finalize/closure_with_finalize_fail.leo @@ -10,14 +10,18 @@ function foo(a: u8, b: u8) -> u8 { function bar(a: u8, b: u8) -> u8 { return a + b; -} finalize(a: u8, b: u8) -> u8 { +} + +finalize bar(a: u8, b: u8) -> u8 { return a + b; } function mint_public(receiver: address, amount: u64) { finalize(receiver, amount); -} finalize (receiver: address, amount: u64) { +} + +finalize mint_public(receiver: address, amount: u64) { increment(account, receiver, amount); } diff --git a/tests/compiler/finalize/decrement.leo b/tests/compiler/finalize/decrement.leo index 48ada76b32..ae16281ac6 100644 --- a/tests/compiler/finalize/decrement.leo +++ b/tests/compiler/finalize/decrement.leo @@ -8,6 +8,8 @@ mapping amounts: address => u128; @program function decrease_self(amount: u128) { finalize(self.caller, amount); -} finalize(addr: address, amount: u128) { +} + +finalize decrease_self(addr: address, amount: u128) { decrement(amounts, addr, amount); } diff --git a/tests/compiler/finalize/decrement_incorrect_type.leo b/tests/compiler/finalize/decrement_incorrect_type.leo index 59dcdf901e..a07f26ffe7 100644 --- a/tests/compiler/finalize/decrement_incorrect_type.leo +++ b/tests/compiler/finalize/decrement_incorrect_type.leo @@ -15,7 +15,9 @@ mapping tokens: address => Token; @program function decrease_self(amount: u128) { finalize(self.caller, amount); -} finalize(addr: address, amount: u128) { +} + +finalize decrease_self(addr: address, amount: u128) { decrement(tokens, addr, amount); decrement(amounts, 1u8, amount); decrement(amounts, addr, 1u8); diff --git a/tests/compiler/finalize/empty_finalize_fail.leo b/tests/compiler/finalize/empty_finalize_fail.leo index 537940e308..aaad487ee4 100644 --- a/tests/compiler/finalize/empty_finalize_fail.leo +++ b/tests/compiler/finalize/empty_finalize_fail.leo @@ -7,4 +7,6 @@ expectation: Fail @program function mint_public(public receiver: address, public amount: u64) { finalize(receiver, amount); -} finalize (public receiver: address, public amount: u64) {} +} + +finalize mint_public (public receiver: address, public amount: u64) {} diff --git a/tests/compiler/finalize/finalize.leo b/tests/compiler/finalize/finalize.leo index 22135b95d3..2286a3f8ed 100644 --- a/tests/compiler/finalize/finalize.leo +++ b/tests/compiler/finalize/finalize.leo @@ -9,21 +9,25 @@ mapping values: u8 => u8; @program function mint_public(public receiver: address, public amount: u64) { finalize(receiver, amount); -} finalize (public receiver: address, public amount: u64) { +} + +finalize mint_public (public receiver: address, public amount: u64) { increment(account, receiver, amount); } @program function public_adder(public a: u8, public b: u8) { finalize(a, b); -} finalize(a: u8, b: u8) -> public u8 { +} finalize public_adder(a: u8, b: u8) -> public u8 { return a + b; } @program function finalize_no_params() { finalize(); -} finalize() { +} + +finalize finalize_no_params() { increment(values, 0u8, 1u8); increment(account, self.caller, 1u64); } diff --git a/tests/compiler/finalize/finalize_incorrect_modes_fail.leo b/tests/compiler/finalize/finalize_incorrect_modes_fail.leo index 541ed934a6..66f5481915 100644 --- a/tests/compiler/finalize/finalize_incorrect_modes_fail.leo +++ b/tests/compiler/finalize/finalize_incorrect_modes_fail.leo @@ -8,14 +8,18 @@ mapping account: address => u64; @program function mint_public(public receiver: address, public amount: u64) { finalize(receiver, amount); -} finalize (public receiver: address, constant amount: u64) -> constant u64 { +} + +finalize mint_public (public receiver: address, constant amount: u64) -> constant u64 { increment(account, receiver, amount); } @program function mint_public2(public receiver: address, public amount: u64) { finalize(receiver, amount); -} finalize (public receiver: address, amount: u64) -> u64 { +} + +finalize mint_public2(public receiver: address, amount: u64) -> u64 { increment(account, receiver, amount); return amount + amount; } diff --git a/tests/compiler/finalize/finalize_incorrect_return_fail.leo b/tests/compiler/finalize/finalize_incorrect_return_fail.leo index a18f78683b..db7a6a3ff8 100644 --- a/tests/compiler/finalize/finalize_incorrect_return_fail.leo +++ b/tests/compiler/finalize/finalize_incorrect_return_fail.leo @@ -8,7 +8,9 @@ mapping account: address => u64; @program function mint_public(public receiver: address, public amount: u64) { finalize(receiver, amount); -} finalize (public receiver: address, public amount: u64) -> u64 { +} + +finalize mint_public(public receiver: address, public amount: u64) -> u64 { increment(account, receiver, amount); return 1u8 + 2u8; } diff --git a/tests/compiler/finalize/finalize_missing_return_fail.leo b/tests/compiler/finalize/finalize_missing_return_fail.leo index bf17cf93b6..77a29be7f8 100644 --- a/tests/compiler/finalize/finalize_missing_return_fail.leo +++ b/tests/compiler/finalize/finalize_missing_return_fail.leo @@ -9,6 +9,8 @@ mapping account: address => u64; @program function mint_public(public receiver: address, public amount: u64) { finalize(receiver, amount); -} finalize (public receiver: address, public amount: u64) -> u64 { +} + +finalize mint_public (public receiver: address, public amount: u64) -> u64 { increment(account, receiver, amount); } diff --git a/tests/compiler/finalize/finalize_name_mismatch_fail.leo b/tests/compiler/finalize/finalize_name_mismatch_fail.leo new file mode 100644 index 0000000000..1ed395becf --- /dev/null +++ b/tests/compiler/finalize/finalize_name_mismatch_fail.leo @@ -0,0 +1,17 @@ +/* +namespace: Compile +expectation: Fail +*/ + +mapping account: address => u64; +mapping values: u8 => u8; + +@program +function mint_public(public receiver: address, public amount: u64) { + finalize(receiver, amount); +} + +finalize mint_private (public receiver: address, public amount: u64) { + increment(account, receiver, amount); +} + diff --git a/tests/compiler/finalize/finalize_statement_incorrect_args_fail.leo b/tests/compiler/finalize/finalize_statement_incorrect_args_fail.leo index 2605f2328b..96abb0ba26 100644 --- a/tests/compiler/finalize/finalize_statement_incorrect_args_fail.leo +++ b/tests/compiler/finalize/finalize_statement_incorrect_args_fail.leo @@ -9,6 +9,8 @@ mapping account: address => u64; @program function mint_public(public receiver: address, public amount: u64) { finalize(receiver, amount, amount); -} finalize (public receiver: address, public amount: u64) { +} + +finalize mint_public (public receiver: address, public amount: u64) { increment(account, receiver, amount); } diff --git a/tests/compiler/finalize/finalize_without_finalize_statement_fail.leo b/tests/compiler/finalize/finalize_without_finalize_statement_fail.leo index a5fb95bfa4..50aff6e6f7 100644 --- a/tests/compiler/finalize/finalize_without_finalize_statement_fail.leo +++ b/tests/compiler/finalize/finalize_without_finalize_statement_fail.leo @@ -8,6 +8,8 @@ mapping account: address => u64; @program function mint_public(public receiver: address, public amount: u64) { -} finalize (public receiver: address, public amount: u64) { +} + +finalize mint_public (public receiver: address, public amount: u64) { increment(account, receiver, amount); } diff --git a/tests/compiler/finalize/increment.leo b/tests/compiler/finalize/increment.leo index f9948a014b..6b4fbc08aa 100644 --- a/tests/compiler/finalize/increment.leo +++ b/tests/compiler/finalize/increment.leo @@ -8,6 +8,8 @@ mapping amounts: address => u128; @program function increase_self(amount: u128) { finalize(self.caller, amount); -} finalize(addr: address, amount: u128) { +} + +finalize increase_self(addr: address, amount: u128) { increment(amounts, addr, amount); } diff --git a/tests/compiler/finalize/increment_incorrect_type.leo b/tests/compiler/finalize/increment_incorrect_type.leo index 116e0ceae5..a8043b581d 100644 --- a/tests/compiler/finalize/increment_incorrect_type.leo +++ b/tests/compiler/finalize/increment_incorrect_type.leo @@ -15,7 +15,9 @@ mapping tokens: address => Token; @program function increase_self(amount: u128) { finalize(self.caller, amount); -} finalize(addr: address, amount: u128) { +} + +finalize increase_self(addr: address, amount: u128) { increment(tokens, addr, amount); increment(amounts, 1u8, amount); increment(amounts, addr, 1u8); diff --git a/tests/compiler/finalize/read_write_mapping_fail.leo b/tests/compiler/finalize/read_write_mapping_fail.leo index ae125a13cb..1e0e4b7ada 100644 --- a/tests/compiler/finalize/read_write_mapping_fail.leo +++ b/tests/compiler/finalize/read_write_mapping_fail.leo @@ -15,12 +15,16 @@ function write(public addr: address, public amount: u128) { function read_in_finalize(public addr: address) { finalize(addr); -} finalize(public addr: address) -> public u128 { +} + +finalize read_in_finalize(public addr: address) -> public u128 { return balances[addr]; } function write_in_finalize(public addr: address, public amount: u128) { finalize(addr, amount); -} finalize(public: addr: address, public amount: u128) { +} + +finalize write_in_finalize(public: addr: address, public amount: u128) { balances[addr] = amount; } diff --git a/tests/compiler/function/self.leo b/tests/compiler/function/self.leo index 38a4923294..e48a00dcb1 100644 --- a/tests/compiler/function/self.leo +++ b/tests/compiler/function/self.leo @@ -7,6 +7,6 @@ expectation: Pass function matches(addr: address) -> bool { finalize(self.caller); return self.caller == addr; -} finalize(addr: address) -> bool { +} finalize matches(addr: address) -> bool { return addr == self.caller; } diff --git a/tests/expectations/compiler/finalize/closure_with_finalize_fail.out b/tests/expectations/compiler/finalize/closure_with_finalize_fail.out index 706b2ab829..c6f5ea6982 100644 --- a/tests/expectations/compiler/finalize/closure_with_finalize_fail.out +++ b/tests/expectations/compiler/finalize/closure_with_finalize_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372036]: Cannot use a `finalize` statement without a `finalize` block.\n --> compiler-test:4:5\n |\n 4 | finalize(a, b);\n | ^^^^^^^^^^^^^^\nError [ETYC0372044]: Function must contain a `finalize` statement on all execution paths.\n --> compiler-test:8:1\n |\n 8 | function bar(a: u8, b: u8) -> u8 {\n 9 | return a + b;\n 10 | } finalize(a: u8, b: u8) -> u8 {\n | ^\nError [ETYC0372032]: Only program functions can have a `finalize` block.\n --> compiler-test:10:3\n |\n 10 | } finalize(a: u8, b: u8) -> u8 {\n 11 | return a + b;\n 12 | }\n | ^\n |\n = Remove the `finalize` block or add a `@program` annotation to the function.\nError [ETYC0372032]: Only program functions can have a `finalize` block.\n --> compiler-test:17:3\n |\n 17 | } finalize (receiver: address, amount: u64) {\n 18 | increment(account, receiver, amount);\n 19 | }\n | ^\n |\n = Remove the `finalize` block or add a `@program` annotation to the function.\nError [ETYC0372005]: Unknown variable `account`\n --> compiler-test:18:15\n |\n 18 | increment(account, receiver, amount);\n | ^^^^^^^\nError [ETYC0372004]: Could not determine the type of `account`\n --> compiler-test:18:15\n |\n 18 | increment(account, receiver, amount);\n | ^^^^^^^\n" + - "Error [ETYC0372036]: Cannot use a `finalize` statement without a `finalize` block.\n --> compiler-test:4:5\n |\n 4 | finalize(a, b);\n | ^^^^^^^^^^^^^^\nError [ETYC0372044]: Function must contain a `finalize` statement on all execution paths.\n --> compiler-test:8:1\n |\n 8 | function bar(a: u8, b: u8) -> u8 {\n 9 | return a + b;\n 10 | }\n | ^\nError [ETYC0372032]: Only program functions can have a `finalize` block.\n --> compiler-test:12:1\n |\n 12 | finalize bar(a: u8, b: u8) -> u8 {\n 13 | return a + b;\n 14 | }\n | ^\n |\n = Remove the `finalize` block or add a `@program` annotation to the function.\nError [ETYC0372032]: Only program functions can have a `finalize` block.\n --> compiler-test:21:1\n |\n 21 | finalize mint_public(receiver: address, amount: u64) {\n 22 | increment(account, receiver, amount);\n 23 | }\n | ^\n |\n = Remove the `finalize` block or add a `@program` annotation to the function.\nError [ETYC0372005]: Unknown variable `account`\n --> compiler-test:22:15\n |\n 22 | increment(account, receiver, amount);\n | ^^^^^^^\nError [ETYC0372004]: Could not determine the type of `account`\n --> compiler-test:22:15\n |\n 22 | increment(account, receiver, amount);\n | ^^^^^^^\n" diff --git a/tests/expectations/compiler/finalize/decrement.out b/tests/expectations/compiler/finalize/decrement.out index c8151cfc8b..3303a40be5 100644 --- a/tests/expectations/compiler/finalize/decrement.out +++ b/tests/expectations/compiler/finalize/decrement.out @@ -4,7 +4,7 @@ expectation: Pass outputs: - output: - initial_input_ast: no input - initial_ast: 022cd27009ad96789db8d4750958d209695834ae378b675d8745ab0629e49a58 - unrolled_ast: 022cd27009ad96789db8d4750958d209695834ae378b675d8745ab0629e49a58 - ssa_ast: 022cd27009ad96789db8d4750958d209695834ae378b675d8745ab0629e49a58 - flattened_ast: 908aa988f2726d06c2799c427c97a8211bdac5e1c76f8afddf9da2f7cd02a04d + initial_ast: e4d86cd0b7831c3de0304190f5af8f1ef7d8e29d1bdacb6d35381ba0e479d6ab + unrolled_ast: e4d86cd0b7831c3de0304190f5af8f1ef7d8e29d1bdacb6d35381ba0e479d6ab + ssa_ast: e4d86cd0b7831c3de0304190f5af8f1ef7d8e29d1bdacb6d35381ba0e479d6ab + flattened_ast: 0ba4b1ecf6e5ebe0c7b7ed0ba10d9830902d7a492c2000fef2cf67e4b43b063a diff --git a/tests/expectations/compiler/finalize/decrement_incorrect_type.out b/tests/expectations/compiler/finalize/decrement_incorrect_type.out index 8ca517207e..fb93422db9 100644 --- a/tests/expectations/compiler/finalize/decrement_incorrect_type.out +++ b/tests/expectations/compiler/finalize/decrement_incorrect_type.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372007]: Expected one type from `Token`, but got `u128`\n --> compiler-test:16:29\n |\n 16 | decrement(tokens, addr, amount);\n | ^^^^^^\nError [ETYC0372007]: Expected one type from `address`, but got `u8`\n --> compiler-test:17:24\n |\n 17 | decrement(amounts, 1u8, amount);\n | ^^^\nError [ETYC0372007]: Expected one type from `u128`, but got `u8`\n --> compiler-test:18:30\n |\n 18 | decrement(amounts, addr, 1u8);\n | ^^^\nError [ETYC0372003]: Expected type `u64` but type `u8` was found\n --> compiler-test:19:57\n |\n 19 | decrement(tokens, addr, Token { owner: addr, gates: 1u8, amount: 1u8 });\n | ^^^\nError [ETYC0372003]: Expected type `u128` but type `u8` was found\n --> compiler-test:19:70\n |\n 19 | decrement(tokens, addr, Token { owner: addr, gates: 1u8, amount: 1u8 });\n | ^^^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128`, but got `Token`\n --> compiler-test:19:29\n |\n 19 | decrement(tokens, addr, Token { owner: addr, gates: 1u8, amount: 1u8 });\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372005]: Unknown variable `foo`\n --> compiler-test:20:15\n |\n 20 | decrement(foo, addr, amount);\n | ^^^\nError [ETYC0372004]: Could not determine the type of `foo`\n --> compiler-test:20:15\n |\n 20 | decrement(foo, addr, amount);\n | ^^^\n" + - "Error [ETYC0372007]: Expected one type from `Token`, but got `u128`\n --> compiler-test:18:29\n |\n 18 | decrement(tokens, addr, amount);\n | ^^^^^^\nError [ETYC0372007]: Expected one type from `address`, but got `u8`\n --> compiler-test:19:24\n |\n 19 | decrement(amounts, 1u8, amount);\n | ^^^\nError [ETYC0372007]: Expected one type from `u128`, but got `u8`\n --> compiler-test:20:30\n |\n 20 | decrement(amounts, addr, 1u8);\n | ^^^\nError [ETYC0372003]: Expected type `u64` but type `u8` was found\n --> compiler-test:21:57\n |\n 21 | decrement(tokens, addr, Token { owner: addr, gates: 1u8, amount: 1u8 });\n | ^^^\nError [ETYC0372003]: Expected type `u128` but type `u8` was found\n --> compiler-test:21:70\n |\n 21 | decrement(tokens, addr, Token { owner: addr, gates: 1u8, amount: 1u8 });\n | ^^^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128`, but got `Token`\n --> compiler-test:21:29\n |\n 21 | decrement(tokens, addr, Token { owner: addr, gates: 1u8, amount: 1u8 });\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372005]: Unknown variable `foo`\n --> compiler-test:22:15\n |\n 22 | decrement(foo, addr, amount);\n | ^^^\nError [ETYC0372004]: Could not determine the type of `foo`\n --> compiler-test:22:15\n |\n 22 | decrement(foo, addr, amount);\n | ^^^\n" diff --git a/tests/expectations/compiler/finalize/empty_finalize_fail.out b/tests/expectations/compiler/finalize/empty_finalize_fail.out index a5102c0687..c533366191 100644 --- a/tests/expectations/compiler/finalize/empty_finalize_fail.out +++ b/tests/expectations/compiler/finalize/empty_finalize_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372039]: A finalize block cannot be empty.\n --> compiler-test:7:3\n |\n 7 | } finalize (public receiver: address, public amount: u64) {}\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Error [ETYC0372039]: A finalize block cannot be empty.\n --> compiler-test:9:1\n |\n 9 | finalize mint_public (public receiver: address, public amount: u64) {}\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" diff --git a/tests/expectations/compiler/finalize/finalize.out b/tests/expectations/compiler/finalize/finalize.out index 92816cfd08..6285a8e513 100644 --- a/tests/expectations/compiler/finalize/finalize.out +++ b/tests/expectations/compiler/finalize/finalize.out @@ -4,7 +4,7 @@ expectation: Pass outputs: - output: - initial_input_ast: no input - initial_ast: c9e084be45c5c97ca9f50605eb3538040835b7ad5b129ada52730a4e8a433bfc - unrolled_ast: c9e084be45c5c97ca9f50605eb3538040835b7ad5b129ada52730a4e8a433bfc - ssa_ast: fefd308cd8d81d806ff62744c9d0b13e2e1abd07c5fb47b22f24134db93c1fea - flattened_ast: 51901b381465e30faad967182dd9dd3a6b9fc013201200b8834f31ce3c398c88 + initial_ast: 8d3492275b704c017c6b9053d267e54ac3374934423cb2b8c5e55bb7e8ecc033 + unrolled_ast: 8d3492275b704c017c6b9053d267e54ac3374934423cb2b8c5e55bb7e8ecc033 + ssa_ast: 6c17d90ec3d2b7acf165ca2ab04e30bf8a49cb3d110ee38e7130eeaa9b0754ee + flattened_ast: 4633594269a408f79ac385ab5d4b41b2b8b9cc69c29ea6d96761be5bd64fe2ef diff --git a/tests/expectations/compiler/finalize/finalize_incorrect_modes_fail.out b/tests/expectations/compiler/finalize/finalize_incorrect_modes_fail.out index fc1602b19a..efab044566 100644 --- a/tests/expectations/compiler/finalize/finalize_incorrect_modes_fail.out +++ b/tests/expectations/compiler/finalize/finalize_incorrect_modes_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372033]: An input to a finalize block must be public.\n --> compiler-test:8:48\n |\n 8 | } finalize (public receiver: address, constant amount: u64) -> constant u64 {\n | ^^^^^^\n |\n = Add a `public` modifier to the input variable declaration or remove the visibility modifier entirely.\nError [ETYC0372033]: An input to a finalize block must be public.\n --> compiler-test:8:73\n |\n 8 | } finalize (public receiver: address, constant amount: u64) -> constant u64 {\n | ^^^\n |\n = Add a `public` modifier to the input variable declaration or remove the visibility modifier entirely.\nError [ETYC0372038]: Function must return a value.\n --> compiler-test:8:3\n |\n 8 | } finalize (public receiver: address, constant amount: u64) -> constant u64 {\n 9 | increment(account, receiver, amount);\n 10 | }\n | ^\n" + - "Error [ETYC0372033]: An input to a finalize block must be public.\n --> compiler-test:10:58\n |\n 10 | finalize mint_public (public receiver: address, constant amount: u64) -> constant u64 {\n | ^^^^^^\n |\n = Add a `public` modifier to the input variable declaration or remove the visibility modifier entirely.\nError [ETYC0372033]: An input to a finalize block must be public.\n --> compiler-test:10:83\n |\n 10 | finalize mint_public (public receiver: address, constant amount: u64) -> constant u64 {\n | ^^^\n |\n = Add a `public` modifier to the input variable declaration or remove the visibility modifier entirely.\nError [ETYC0372038]: Function must return a value.\n --> compiler-test:10:1\n |\n 10 | finalize mint_public (public receiver: address, constant amount: u64) -> constant u64 {\n 11 | increment(account, receiver, amount);\n 12 | }\n | ^\n" diff --git a/tests/expectations/compiler/finalize/finalize_incorrect_return_fail.out b/tests/expectations/compiler/finalize/finalize_incorrect_return_fail.out index c60d7b6b74..262bd36b3f 100644 --- a/tests/expectations/compiler/finalize/finalize_incorrect_return_fail.out +++ b/tests/expectations/compiler/finalize/finalize_incorrect_return_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372003]: Expected type `u64` but type `u8` was found\n --> compiler-test:10:12\n |\n 10 | return 1u8 + 2u8;\n | ^^^\nError [ETYC0372003]: Expected type `u64` but type `u8` was found\n --> compiler-test:10:18\n |\n 10 | return 1u8 + 2u8;\n | ^^^\n" + - "Error [ETYC0372003]: Expected type `u64` but type `u8` was found\n --> compiler-test:12:12\n |\n 12 | return 1u8 + 2u8;\n | ^^^\nError [ETYC0372003]: Expected type `u64` but type `u8` was found\n --> compiler-test:12:18\n |\n 12 | return 1u8 + 2u8;\n | ^^^\n" diff --git a/tests/expectations/compiler/finalize/finalize_missing_return_fail.out b/tests/expectations/compiler/finalize/finalize_missing_return_fail.out index 02722e6b69..8416a8fdb6 100644 --- a/tests/expectations/compiler/finalize/finalize_missing_return_fail.out +++ b/tests/expectations/compiler/finalize/finalize_missing_return_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372038]: Function must return a value.\n --> compiler-test:9:3\n |\n 9 | } finalize (public receiver: address, public amount: u64) -> u64 {\n 10 | increment(account, receiver, amount);\n 11 | }\n | ^\n" + - "Error [ETYC0372038]: Function must return a value.\n --> compiler-test:11:1\n |\n 11 | finalize mint_public (public receiver: address, public amount: u64) -> u64 {\n 12 | increment(account, receiver, amount);\n 13 | }\n | ^\n" diff --git a/tests/expectations/compiler/finalize/finalize_name_mismatch_fail.out b/tests/expectations/compiler/finalize/finalize_name_mismatch_fail.out new file mode 100644 index 0000000000..1fb2017511 --- /dev/null +++ b/tests/expectations/compiler/finalize/finalize_name_mismatch_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [ETYC0372045]: `finalize` name `mint_public` does not match function name `mint_private`\n --> compiler-test:11:1\n |\n 11 | finalize mint_private (public receiver: address, public amount: u64) {\n 12 | increment(account, receiver, amount);\n 13 | }\n | ^\n" diff --git a/tests/expectations/compiler/finalize/finalize_without_finalize_statement_fail.out b/tests/expectations/compiler/finalize/finalize_without_finalize_statement_fail.out index 2b27a6f241..8854f82f53 100644 --- a/tests/expectations/compiler/finalize/finalize_without_finalize_statement_fail.out +++ b/tests/expectations/compiler/finalize/finalize_without_finalize_statement_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372044]: Function must contain a `finalize` statement on all execution paths.\n --> compiler-test:6:1\n |\n 6 | function mint_public(public receiver: address, public amount: u64) {\n 7 | \n 8 | } finalize (public receiver: address, public amount: u64) {\n | ^\n" + - "Error [ETYC0372044]: Function must contain a `finalize` statement on all execution paths.\n --> compiler-test:6:1\n |\n 6 | function mint_public(public receiver: address, public amount: u64) {\n 7 | \n 8 | }\n | ^\n" diff --git a/tests/expectations/compiler/finalize/increment.out b/tests/expectations/compiler/finalize/increment.out index c0bdb4000d..de41103b32 100644 --- a/tests/expectations/compiler/finalize/increment.out +++ b/tests/expectations/compiler/finalize/increment.out @@ -4,7 +4,7 @@ expectation: Pass outputs: - output: - initial_input_ast: no input - initial_ast: 8a81d647da7c5f607d8166d16147a89f02a7003bd94d4f73ab171f57bfa91486 - unrolled_ast: 8a81d647da7c5f607d8166d16147a89f02a7003bd94d4f73ab171f57bfa91486 - ssa_ast: 8a81d647da7c5f607d8166d16147a89f02a7003bd94d4f73ab171f57bfa91486 - flattened_ast: 011a203c102febe366eb116d0f8f29d4b9453c3dcfc02d26b07ae5022aad64ee + initial_ast: 743ef643d0205706e875c7eb3a4fc5866e8a3e6b6c43388c36be418a0f37773c + unrolled_ast: 743ef643d0205706e875c7eb3a4fc5866e8a3e6b6c43388c36be418a0f37773c + ssa_ast: 743ef643d0205706e875c7eb3a4fc5866e8a3e6b6c43388c36be418a0f37773c + flattened_ast: 7678967d822f0d82683ca4c01410377bd53e3ce78da126d0c07b651722c23be4 diff --git a/tests/expectations/compiler/finalize/increment_incorrect_type.out b/tests/expectations/compiler/finalize/increment_incorrect_type.out index ecf75b5b93..7b5e30c3b4 100644 --- a/tests/expectations/compiler/finalize/increment_incorrect_type.out +++ b/tests/expectations/compiler/finalize/increment_incorrect_type.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372007]: Expected one type from `Token`, but got `u128`\n --> compiler-test:16:29\n |\n 16 | increment(tokens, addr, amount);\n | ^^^^^^\nError [ETYC0372007]: Expected one type from `address`, but got `u8`\n --> compiler-test:17:24\n |\n 17 | increment(amounts, 1u8, amount);\n | ^^^\nError [ETYC0372007]: Expected one type from `u128`, but got `u8`\n --> compiler-test:18:30\n |\n 18 | increment(amounts, addr, 1u8);\n | ^^^\nError [ETYC0372007]: Expected one type from `u128`, but got `Token`\n --> compiler-test:19:30\n |\n 19 | increment(amounts, addr, Token { owner: addr, gates: 1u64, amount: amount });\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128`, but got `Token`\n --> compiler-test:19:30\n |\n 19 | increment(amounts, addr, Token { owner: addr, gates: 1u64, amount: amount });\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372005]: Unknown variable `foo`\n --> compiler-test:20:15\n |\n 20 | increment(foo, addr, amount);\n | ^^^\nError [ETYC0372004]: Could not determine the type of `foo`\n --> compiler-test:20:15\n |\n 20 | increment(foo, addr, amount);\n | ^^^\n" + - "Error [ETYC0372007]: Expected one type from `Token`, but got `u128`\n --> compiler-test:18:29\n |\n 18 | increment(tokens, addr, amount);\n | ^^^^^^\nError [ETYC0372007]: Expected one type from `address`, but got `u8`\n --> compiler-test:19:24\n |\n 19 | increment(amounts, 1u8, amount);\n | ^^^\nError [ETYC0372007]: Expected one type from `u128`, but got `u8`\n --> compiler-test:20:30\n |\n 20 | increment(amounts, addr, 1u8);\n | ^^^\nError [ETYC0372007]: Expected one type from `u128`, but got `Token`\n --> compiler-test:21:30\n |\n 21 | increment(amounts, addr, Token { owner: addr, gates: 1u64, amount: amount });\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128`, but got `Token`\n --> compiler-test:21:30\n |\n 21 | increment(amounts, addr, Token { owner: addr, gates: 1u64, amount: amount });\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372005]: Unknown variable `foo`\n --> compiler-test:22:15\n |\n 22 | increment(foo, addr, amount);\n | ^^^\nError [ETYC0372004]: Could not determine the type of `foo`\n --> compiler-test:22:15\n |\n 22 | increment(foo, addr, amount);\n | ^^^\n" diff --git a/tests/expectations/compiler/function/self.out b/tests/expectations/compiler/function/self.out index 52c3aa25f0..999886b0dc 100644 --- a/tests/expectations/compiler/function/self.out +++ b/tests/expectations/compiler/function/self.out @@ -4,7 +4,7 @@ expectation: Pass outputs: - output: - initial_input_ast: no input - initial_ast: 7ed7d6319260b00ad492163d5ad3f01a55b4ec673ddec3f9c7e476828c6b0333 - unrolled_ast: 7ed7d6319260b00ad492163d5ad3f01a55b4ec673ddec3f9c7e476828c6b0333 - ssa_ast: e3b3836ac5dd7e8f61f99b0d2d5c95ddae98ff442b6412aed160d20e82713ed3 - flattened_ast: f78c9aa1e48af5f9e37209084f43d8ee49ff7e4eaa45ca1576e38a1646ed11cd + initial_ast: 3a0d71d0af8ada3d9e96047c25a92f4aac411ddee1f850dbab43ec547b0f57f2 + unrolled_ast: 3a0d71d0af8ada3d9e96047c25a92f4aac411ddee1f850dbab43ec547b0f57f2 + ssa_ast: 66fb0ed53a9a0229b39b04e364412d1099f5f234f4de7ba8b2935326bf2c9772 + flattened_ast: 1dd4aafdb00294c787d8fb18365c1125b1b768b386e067b5ff84dfcbd63319b6 diff --git a/tests/expectations/compiler/mapping/mapping.out b/tests/expectations/compiler/mapping/mapping.out deleted file mode 100644 index 28d2749628..0000000000 --- a/tests/expectations/compiler/mapping/mapping.out +++ /dev/null @@ -1,10 +0,0 @@ ---- -namespace: Compile -expectation: Pass -outputs: - - output: - - initial_input_ast: no input - initial_ast: 9189741b2869eb997eb860472a2b47f7247e750f5c2ca0d97d211a6d4f87d3f5 - unrolled_ast: 9189741b2869eb997eb860472a2b47f7247e750f5c2ca0d97d211a6d4f87d3f5 - ssa_ast: 9189741b2869eb997eb860472a2b47f7247e750f5c2ca0d97d211a6d4f87d3f5 - flattened_ast: 9189741b2869eb997eb860472a2b47f7247e750f5c2ca0d97d211a6d4f87d3f5 diff --git a/tests/expectations/compiler/mapping/mapping_fail.out b/tests/expectations/compiler/mapping/mapping_fail.out deleted file mode 100644 index b6e3242cb0..0000000000 --- a/tests/expectations/compiler/mapping/mapping_fail.out +++ /dev/null @@ -1,5 +0,0 @@ ---- -namespace: Compile -expectation: Fail -outputs: - - "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- found '('\n --> compiler-test:3:14\n |\n 3 | mapping foo: (u32, u32) => u32;\n | ^" diff --git a/tests/expectations/compiler/mapping/simple_mapping.out b/tests/expectations/compiler/mapping/simple_mapping.out deleted file mode 100644 index 9b4394cf33..0000000000 --- a/tests/expectations/compiler/mapping/simple_mapping.out +++ /dev/null @@ -1,9 +0,0 @@ ---- -namespace: Compile -expectation: Pass -outputs: - - output: - - initial_input_ast: no input - initial_ast: 40dc8ad2ebf4af78e20722af3a6772e22254724fe566e4c7232949c87f010813 - unrolled_ast: 40dc8ad2ebf4af78e20722af3a6772e22254724fe566e4c7232949c87f010813 - ssa_ast: 40dc8ad2ebf4af78e20722af3a6772e22254724fe566e4c7232949c87f010813 diff --git a/tests/expectations/compiler/mapping/tuple_mapping_fail.out b/tests/expectations/compiler/mapping/tuple_mapping_fail.out deleted file mode 100644 index 9817ba0a5e..0000000000 --- a/tests/expectations/compiler/mapping/tuple_mapping_fail.out +++ /dev/null @@ -1,5 +0,0 @@ ---- -namespace: Compile -expectation: Fail -outputs: - - "Error [ETYC0372031]: A mapping's key cannot be a tuple\n --> compiler-test:3:1\n |\n 3 | mapping foo: (u32, u32) => u32;\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" diff --git a/tests/expectations/parser/finalize/finalize.out b/tests/expectations/parser/finalize/finalize.out index 866fe8d804..c810074b9a 100644 --- a/tests/expectations/parser/finalize/finalize.out +++ b/tests/expectations/parser/finalize/finalize.out @@ -26,69 +26,71 @@ outputs: lo: 26 hi: 30 finalize: + identifier: "{\"name\":\"main\",\"span\":\"{\\\"lo\\\":41,\\\"hi\\\":45}\"}" input: [] output: [] output_type: Unit block: statements: [] span: - lo: 42 - hi: 46 + lo: 48 + hi: 52 span: - lo: 31 - hi: 46 + lo: 32 + hi: 52 span: lo: 2 hi: 30 - "{\"name\":\"main\",\"span\":\"{\\\"lo\\\":57,\\\"hi\\\":61}\"}": + "{\"name\":\"main\",\"span\":\"{\\\"lo\\\":63,\\\"hi\\\":67}\"}": annotations: [] - identifier: "{\"name\":\"main\",\"span\":\"{\\\"lo\\\":57,\\\"hi\\\":61}\"}" + identifier: "{\"name\":\"main\",\"span\":\"{\\\"lo\\\":63,\\\"hi\\\":67}\"}" input: [] output: - mode: None type_: Boolean span: - lo: 67 - hi: 71 + lo: 73 + hi: 77 output_type: Boolean block: statements: [] span: - lo: 72 - hi: 76 + lo: 78 + hi: 82 finalize: + identifier: "{\"name\":\"main\",\"span\":\"{\\\"lo\\\":92,\\\"hi\\\":96}\"}" input: - - identifier: "{\"name\":\"a\",\"span\":\"{\\\"lo\\\":86,\\\"hi\\\":87}\"}" + - identifier: "{\"name\":\"a\",\"span\":\"{\\\"lo\\\":97,\\\"hi\\\":98}\"}" mode: None type_: - Identifier: "{\"name\":\"foo\",\"span\":\"{\\\"lo\\\":89,\\\"hi\\\":92}\"}" + Identifier: "{\"name\":\"foo\",\"span\":\"{\\\"lo\\\":100,\\\"hi\\\":103}\"}" span: - lo: 86 - hi: 87 - - identifier: "{\"name\":\"b\",\"span\":\"{\\\"lo\\\":94,\\\"hi\\\":95}\"}" + lo: 97 + hi: 98 + - identifier: "{\"name\":\"b\",\"span\":\"{\\\"lo\\\":105,\\\"hi\\\":106}\"}" mode: None type_: - Identifier: "{\"name\":\"bar\",\"span\":\"{\\\"lo\\\":97,\\\"hi\\\":100}\"}" + Identifier: "{\"name\":\"bar\",\"span\":\"{\\\"lo\\\":108,\\\"hi\\\":111}\"}" span: - lo: 94 - hi: 95 + lo: 105 + hi: 106 output: - mode: None type_: - Identifier: "{\"name\":\"baz\",\"span\":\"{\\\"lo\\\":105,\\\"hi\\\":108}\"}" + Identifier: "{\"name\":\"baz\",\"span\":\"{\\\"lo\\\":116,\\\"hi\\\":119}\"}" span: - lo: 105 - hi: 108 + lo: 116 + hi: 119 output_type: - Identifier: "{\"name\":\"baz\",\"span\":\"{\\\"lo\\\":105,\\\"hi\\\":108}\"}" + Identifier: "{\"name\":\"baz\",\"span\":\"{\\\"lo\\\":116,\\\"hi\\\":119}\"}" block: statements: [] span: - lo: 109 - hi: 113 + lo: 120 + hi: 124 span: - lo: 77 - hi: 113 + lo: 83 + hi: 124 span: - lo: 48 - hi: 76 + lo: 54 + hi: 82 diff --git a/tests/expectations/parser/finalize/finalize_fail.out b/tests/expectations/parser/finalize/finalize_fail.out index b04f234489..053bf8d71e 100644 --- a/tests/expectations/parser/finalize/finalize_fail.out +++ b/tests/expectations/parser/finalize/finalize_fail.out @@ -2,4 +2,4 @@ namespace: Parse expectation: Fail outputs: - - "Error [EPAR0370005]: expected ( -- found '{'\n --> test:5:12\n |\n 5 | } finalize {\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'identifier', found '{'\n --> test:5:12\n |\n 5 | } finalize {\n | ^" diff --git a/tests/parser/finalize/finalize.leo b/tests/parser/finalize/finalize.leo index 012746e911..d56d9f3304 100644 --- a/tests/parser/finalize/finalize.leo +++ b/tests/parser/finalize/finalize.leo @@ -5,13 +5,15 @@ expectation: Pass function main() -> bool { -} finalize() { +} + +finalize main() { } function main() -> bool { -} finalize(a: foo, b: bar) -> baz { +} finalize main(a: foo, b: bar) -> baz { } diff --git a/tests/parser/finalize/finalize_fail.leo b/tests/parser/finalize/finalize_fail.leo index 5d83679acf..5fedc9ac80 100644 --- a/tests/parser/finalize/finalize_fail.leo +++ b/tests/parser/finalize/finalize_fail.leo @@ -11,13 +11,19 @@ function main() -> bool { function main() -> bool { +} finalize() { + +} + +function main() -> bool { + } finalie() { } function main() -> bool { -} finalize() floo { +} finalize main() floo { }