Add name to finalize block

This commit is contained in:
Pranav Gaddamadugu 2022-09-13 11:06:24 +02:00
parent 6d35560528
commit c2bed2bb54
46 changed files with 195 additions and 113 deletions

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
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<FunctionInput>,
/// 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<FunctionInput>, output: Vec<FunctionOutput>, block: Block, span: Span) -> Self {
pub fn new(
identifier: Identifier,
input: Vec<FunctionInput>,
output: Vec<FunctionOutput>,
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::<Vec<_>>().join(",")
),
};
write!(f, " finalize({}) -> {} {}", parameters, returns, self.block)
write!(
f,
" finalize {}({}) -> {} {}",
self.identifier, parameters, returns, self.block
)
}
}

View File

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

View File

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

View File

@ -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() {

View File

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

View File

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

View File

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

View File

@ -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();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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) {}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +0,0 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: no input
initial_ast: 40dc8ad2ebf4af78e20722af3a6772e22254724fe566e4c7232949c87f010813
unrolled_ast: 40dc8ad2ebf4af78e20722af3a6772e22254724fe566e4c7232949c87f010813
ssa_ast: 40dc8ad2ebf4af78e20722af3a6772e22254724fe566e4c7232949c87f010813

View File

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

View File

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

View File

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

View File

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

View File

@ -11,13 +11,19 @@ function main() -> bool {
function main() -> bool {
} finalize() {
}
function main() -> bool {
} finalie() {
}
function main() -> bool {
} finalize() floo {
} finalize main() floo {
}