From 003383762dffe29e341bb0552be6272936a2bd58 Mon Sep 17 00:00:00 2001 From: Michael Benfield Date: Sun, 3 Nov 2024 12:57:56 -0800 Subject: [PATCH] Disallow local variables from shadowing functions, structs, mappings, etc. --- .../passes/src/common/symbol_table/mod.rs | 41 +++++++++++++++---- .../src/loop_unrolling/unroll_statement.rs | 12 +++--- .../src/symbol_table_creation/creator.rs | 2 +- .../src/type_checking/check_statements.rs | 24 +++++------ compiler/passes/src/type_checking/checker.rs | 14 +++---- .../transition_calls_async_function_fail.out | 2 +- .../variable_shadow_function_fail.out | 14 +++++++ .../mappings/variable_shadow_mapping_fail.out | 14 +++++++ .../execution/cond_exec_in_finalize.out | 40 +++++++++--------- .../transition_calls_async_function_fail.leo | 2 +- .../variable_shadow_function_fail.leo | 15 +++++++ .../mappings/variable_shadow_mapping_fail.leo | 13 ++++++ .../statements/expr_statement_fail.leo | 2 +- .../tests/execution/cond_exec_in_finalize.leo | 8 ++-- 14 files changed, 140 insertions(+), 63 deletions(-) create mode 100644 tests/expectations/compiler/function/variable_shadow_function_fail.out create mode 100644 tests/expectations/compiler/mappings/variable_shadow_mapping_fail.out create mode 100644 tests/tests/compiler/function/variable_shadow_function_fail.leo create mode 100644 tests/tests/compiler/mappings/variable_shadow_mapping_fail.leo diff --git a/compiler/passes/src/common/symbol_table/mod.rs b/compiler/passes/src/common/symbol_table/mod.rs index cab101120c..acfa2dd01a 100644 --- a/compiler/passes/src/common/symbol_table/mod.rs +++ b/compiler/passes/src/common/symbol_table/mod.rs @@ -56,7 +56,24 @@ pub struct SymbolTable { impl SymbolTable { /// Recursively checks if the symbol table contains an entry for the given symbol. /// Leo does not allow any variable shadowing or overlap between different symbols. - pub fn check_shadowing(&self, location: &Location, is_struct: bool, span: Span) -> Result<()> { + pub fn check_shadowing( + &self, + location: &Location, + program: Option, + is_struct: bool, + span: Span, + ) -> Result<()> { + self.check_shadowing_impl(location, is_struct, span)?; + // Even if the current item is not scoped by program, we want a collision + // if there are program-scoped items with the same name, so check that too. + if program.is_some() && location.program.is_none() { + let location2 = Location::new(program, location.name); + self.check_shadowing_impl(&location2, is_struct, span)?; + } + Ok(()) + } + + fn check_shadowing_impl(&self, location: &Location, is_struct: bool, span: Span) -> Result<()> { if self.functions.contains_key(location) { return Err(AstError::shadowed_function(location.name, span).into()); } else if self.structs.get(location).is_some() && !(location.program.is_none() && is_struct) { @@ -68,7 +85,11 @@ impl SymbolTable { } else if self.variables.contains_key(location) { return Err(AstError::shadowed_variable(location.name, span).into()); } - if let Some(parent) = self.parent.as_ref() { parent.check_shadowing(location, is_struct, span) } else { Ok(()) } + if let Some(parent) = self.parent.as_ref() { + parent.check_shadowing_impl(location, is_struct, span) + } else { + Ok(()) + } } /// Returns the current scope index. @@ -82,7 +103,7 @@ impl SymbolTable { /// Inserts a function into the symbol table. pub fn insert_fn(&mut self, location: Location, insert: &Function) -> Result<()> { let id = self.scope_index(); - self.check_shadowing(&location, false, insert.span)?; + self.check_shadowing(&location, None, false, insert.span)?; self.functions.insert(location, Self::new_function_symbol(id, insert)); self.scopes.push(Default::default()); Ok(()) @@ -91,7 +112,7 @@ impl SymbolTable { /// Inserts a struct into the symbol table. pub fn insert_struct(&mut self, location: Location, insert: &Composite) -> Result<()> { // Check shadowing. - self.check_shadowing(&location, !insert.is_record, insert.span)?; + self.check_shadowing(&location, None, !insert.is_record, insert.span)?; if insert.is_record { // Insert the record into the symbol table. @@ -139,8 +160,13 @@ impl SymbolTable { } /// Inserts a variable into the symbol table. - pub fn insert_variable(&mut self, location: Location, insert: VariableSymbol) -> Result<()> { - self.check_shadowing(&location, false, insert.span)?; + pub fn insert_variable( + &mut self, + location: Location, + program: Option, + insert: VariableSymbol, + ) -> Result<()> { + self.check_shadowing(&location, program, false, insert.span)?; self.variables.insert(location, insert); Ok(()) } @@ -294,6 +320,7 @@ mod tests { symbol_table .insert_variable( Location::new(Some(Symbol::intern("credits")), Symbol::intern("accounts")), + None, VariableSymbol { type_: Type::Address, span: Default::default(), declaration: VariableType::Const }, ) .unwrap(); @@ -308,7 +335,7 @@ mod tests { }) .unwrap(); symbol_table - .insert_variable(Location::new(None, Symbol::intern("foo")), VariableSymbol { + .insert_variable(Location::new(None, Symbol::intern("foo")), None, VariableSymbol { type_: Type::Address, span: Default::default(), declaration: VariableType::Const, diff --git a/compiler/passes/src/loop_unrolling/unroll_statement.rs b/compiler/passes/src/loop_unrolling/unroll_statement.rs index 22b70a87a0..b92d0de03f 100644 --- a/compiler/passes/src/loop_unrolling/unroll_statement.rs +++ b/compiler/passes/src/loop_unrolling/unroll_statement.rs @@ -77,13 +77,11 @@ impl StatementReconstructor for Unroller<'_> { fn reconstruct_definition(&mut self, input: DefinitionStatement) -> (Statement, Self::AdditionalOutput) { // Helper function to add variables to symbol table let insert_variable = |symbol: Symbol, type_: Type, span: Span| { - if let Err(err) = - self.symbol_table.borrow_mut().insert_variable(Location::new(None, symbol), VariableSymbol { - type_, - span, - declaration: VariableType::Mut, - }) - { + if let Err(err) = self.symbol_table.borrow_mut().insert_variable( + Location::new(None, symbol), + self.current_program, + VariableSymbol { type_, span, declaration: VariableType::Mut }, + ) { self.handler.emit_err(err); } }; diff --git a/compiler/passes/src/symbol_table_creation/creator.rs b/compiler/passes/src/symbol_table_creation/creator.rs index 226995a3b4..aac9ae6bda 100644 --- a/compiler/passes/src/symbol_table_creation/creator.rs +++ b/compiler/passes/src/symbol_table_creation/creator.rs @@ -85,7 +85,7 @@ impl<'a> ProgramVisitor<'a> for SymbolTableCreator<'a> { }; // Add the variable associated with the mapping to the symbol table. if let Err(err) = - self.symbol_table.insert_variable(Location::new(program, input.identifier.name), VariableSymbol { + self.symbol_table.insert_variable(Location::new(program, input.identifier.name), None, VariableSymbol { type_: Type::Mapping(MappingType { key: Box::new(input.key_type.clone()), value: Box::new(input.value_type.clone()), diff --git a/compiler/passes/src/type_checking/check_statements.rs b/compiler/passes/src/type_checking/check_statements.rs index fa4c9d046d..ca10467b7e 100644 --- a/compiler/passes/src/type_checking/check_statements.rs +++ b/compiler/passes/src/type_checking/check_statements.rs @@ -224,13 +224,11 @@ impl<'a, N: Network> StatementVisitor<'a> for TypeChecker<'a, N> { self.visit_expression(&input.value, &Some(input.type_.clone())); // Add constants to symbol table so that any references to them in later statements will pass TC - if let Err(err) = - self.symbol_table.borrow_mut().insert_variable(Location::new(None, input.place.name), VariableSymbol { - type_: input.type_.clone(), - span: input.place.span, - declaration: VariableType::Const, - }) - { + if let Err(err) = self.symbol_table.borrow_mut().insert_variable( + Location::new(None, input.place.name), + self.scope_state.program_name, + VariableSymbol { type_: input.type_.clone(), span: input.place.span, declaration: VariableType::Const }, + ) { self.handler.emit_err(err); } } @@ -322,13 +320,11 @@ impl<'a, N: Network> StatementVisitor<'a> for TypeChecker<'a, N> { let scope_index = self.create_child_scope(); // Add the loop variable to the scope of the loop body. - if let Err(err) = - self.symbol_table.borrow_mut().insert_variable(Location::new(None, input.variable.name), VariableSymbol { - type_: input.type_.clone(), - span: input.span(), - declaration: VariableType::Const, - }) - { + if let Err(err) = self.symbol_table.borrow_mut().insert_variable( + Location::new(None, input.variable.name), + self.scope_state.program_name, + VariableSymbol { type_: input.type_.clone(), span: input.span(), declaration: VariableType::Const }, + ) { self.handler.emit_err(err); } diff --git a/compiler/passes/src/type_checking/checker.rs b/compiler/passes/src/type_checking/checker.rs index 0ae942d8b7..dfcd0afc6d 100644 --- a/compiler/passes/src/type_checking/checker.rs +++ b/compiler/passes/src/type_checking/checker.rs @@ -1159,6 +1159,7 @@ impl<'a, N: Network> TypeChecker<'a, N> { // Insert to symbol table if let Err(err) = self.symbol_table.borrow_mut().insert_variable( Location::new(None, t1.identifier().name), + self.scope_state.program_name, VariableSymbol { type_: t2.clone(), span: t1.identifier.span(), @@ -1230,6 +1231,7 @@ impl<'a, N: Network> TypeChecker<'a, N> { if !matches!(&input_var.type_(), &Type::Future(_)) { if let Err(err) = self.symbol_table.borrow_mut().insert_variable( Location::new(None, input_var.identifier().name), + self.scope_state.program_name, VariableSymbol { type_: input_var.type_().clone(), span: input_var.identifier().span(), @@ -1359,13 +1361,11 @@ impl<'a, N: Network> TypeChecker<'a, N> { type_ }; // Insert the variable into the symbol table. - if let Err(err) = - self.symbol_table.borrow_mut().insert_variable(Location::new(None, name.name), VariableSymbol { - type_: ty, - span, - declaration: VariableType::Mut, - }) - { + if let Err(err) = self.symbol_table.borrow_mut().insert_variable( + Location::new(None, name.name), + self.scope_state.program_name, + VariableSymbol { type_: ty, span, declaration: VariableType::Mut }, + ) { self.handler.emit_err(err); } } diff --git a/tests/expectations/compiler/function/transition_calls_async_function_fail.out b/tests/expectations/compiler/function/transition_calls_async_function_fail.out index fca1ade9d5..d426ec5883 100644 --- a/tests/expectations/compiler/function/transition_calls_async_function_fail.out +++ b/tests/expectations/compiler/function/transition_calls_async_function_fail.out @@ -4,7 +4,7 @@ outputs = [""" Error [ETYC0372110]: A `transition` cannot return a future. --> compiler-test:5:35 | - 5 | transition a(a: u64, b: u64) -> Future { + 5 | transition f(a: u64, b: u64) -> Future { | ^^^^^^ | = Use an `async transition` instead. diff --git a/tests/expectations/compiler/function/variable_shadow_function_fail.out b/tests/expectations/compiler/function/variable_shadow_function_fail.out new file mode 100644 index 0000000000..6cc5de45f7 --- /dev/null +++ b/tests/expectations/compiler/function/variable_shadow_function_fail.out @@ -0,0 +1,14 @@ +namespace = "Compile" +expectation = "Fail" +outputs = [""" +Error [EAST0372006]: function `f1` shadowed by + --> compiler-test:9:13 + | + 9 | let f1: u8 = 1u8; + | ^^ +Error [ETYC0372005]: Unknown variable `f1` + --> compiler-test:10:16 + | + 10 | return f1; + | ^^ +"""] diff --git a/tests/expectations/compiler/mappings/variable_shadow_mapping_fail.out b/tests/expectations/compiler/mappings/variable_shadow_mapping_fail.out new file mode 100644 index 0000000000..728171d9b8 --- /dev/null +++ b/tests/expectations/compiler/mappings/variable_shadow_mapping_fail.out @@ -0,0 +1,14 @@ +namespace = "Compile" +expectation = "Fail" +outputs = [""" +Error [EAST0372009]: variable `m` shadowed by + --> compiler-test:7:13 + | + 7 | let m: u8 = 1u8; + | ^ +Error [ETYC0372003]: Expected type `u8` but type `(u8 => u8)` was found + --> compiler-test:8:16 + | + 8 | return m; + | ^ +"""] diff --git a/tests/expectations/execution/cond_exec_in_finalize.out b/tests/expectations/execution/cond_exec_in_finalize.out index 398052bc3b..a788b55ef8 100644 --- a/tests/expectations/execution/cond_exec_in_finalize.out +++ b/tests/expectations/execution/cond_exec_in_finalize.out @@ -1,15 +1,15 @@ namespace = "Execute" expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "17dc9f6dcb320c160ffe1d26761b75b37ee44fe25619f2013fc6bc58b6583db1", type_checked_symbol_table = "1d48096d1a93db0bb2462a54823dfaaedbfec9797947ad5642e106a3e01579e3", unrolled_symbol_table = "1d48096d1a93db0bb2462a54823dfaaedbfec9797947ad5642e106a3e01579e3", initial_ast = "27c7103cf4aef0e2bb8a1abb044f3aa3a02b6d58c08a0f2cca78d13f7b061665", unrolled_ast = "27c7103cf4aef0e2bb8a1abb044f3aa3a02b6d58c08a0f2cca78d13f7b061665", ssa_ast = "5d2d844bb95e6a45dffd4786aa55c2483f7cda49617cb74671e9687c1cb75a74", flattened_ast = "ed13779e30ec49a94037b9091a346e8c583b0e810bd7fd7f66763d81748a50f9", destructured_ast = "5d359e7a833089b922e8120e18495aeaa2c934b3635d049b5a664821e4848ca2", inlined_ast = "c45e0ac0e118cfb19985499297124ec4b036450879a86c7b9deb8e2783d65b8e", dce_ast = "c45e0ac0e118cfb19985499297124ec4b036450879a86c7b9deb8e2783d65b8e", bytecode = """ +outputs = [[{ compile = [{ initial_symbol_table = "3afc5e07a4f230e8f3be40d0ade1920e409327f0f89c43ab2ce4905ec62404a7", type_checked_symbol_table = "64fa45996054e06078ac8da85813cecb72e8fe4feeb7b7c31b143a1c557a993f", unrolled_symbol_table = "64fa45996054e06078ac8da85813cecb72e8fe4feeb7b7c31b143a1c557a993f", initial_ast = "76fd5f0a3605860118f287030e3f100ad0fc3781af331596716f813be64045f9", unrolled_ast = "76fd5f0a3605860118f287030e3f100ad0fc3781af331596716f813be64045f9", ssa_ast = "91a217c212209d7c801917b911bf6d10c6dff22952d6b9af08a4926f374bb4ab", flattened_ast = "a07729b9ca185158b78ba1bba59e34c03bac6f8aab5684b6b84413d684b35b92", destructured_ast = "dd6fa17b6090168db15a731365182bb5247b97ac0f2dc32d2df48970a9111b6f", inlined_ast = "563056c51f60ca6df72cf03ce2f585d59471d3aeb8d6172305ab2b1060899ca1", dce_ast = "563056c51f60ca6df72cf03ce2f585d59471d3aeb8d6172305ab2b1060899ca1", bytecode = """ program cond_exec_in_finalize.aleo; -function a: +function f: input r0 as u64.private; input r1 as u64.private; - async a r0 r1 into r2; - output r2 as cond_exec_in_finalize.aleo/a.future; + async f r0 r1 into r2; + output r2 as cond_exec_in_finalize.aleo/f.future; -finalize a: +finalize f: input r0 as u64.public; input r1 as u64.public; is.eq r1 0u64 into r2; @@ -21,37 +21,37 @@ finalize a: assert.eq r3 1u64; position end_otherwise_0_1; """, errors = "", warnings = "" }], execute = [ - { verified = true, status = "accepted", errors = "", warnings = "", execution = { global_state_root = "sr1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gk0xu", proof = "proof1qyqsqqqqqqqqqqqpqqqqqqqqqqq0rxwjqlxmc8acm0xaxeewz905709n3wjz45gmdpv6q0yy2pqhzj0dj7zaq2x32veqxg2aqveccuyqqys9vejps3830l50n6znqk47m7tf00xv4qnpg9vpz4l45rqs7n2hdyxutqjjd6w3j3le0p64u5dpjq2jhfant7td2w0wrr0r5v762k8lujm2r3rq283jfkl0aqrnfuhhklhxpe5zrhvcndj95p8drpw7fsqggqfk9e40l7nw600kel4p36ggaapgjpzpqlanwuuwlj3mas52p6qefk7xkacgcldxka9saqf4wwgqu9e87lv9jy68fzr65nujqdlxkds23l30nqejxfh0d6ycvvmgfzutps9ggafhelp0vc7zude43yjsrnx3348l4wzgu4nncayjlc88sw60h02lkn79ak8hszv4gqejvdlam4v5ylx5wsde7y5af0jrwkn2qp6st8j0ns5hafgh6mex29dt7ah26clzzmgm6ack4wvq64905ja9xuzsex6rf3uvahk89wzhlzx5eqwq7894l2l0f7vkmglk8d85987qttja0ug87594vxrkaadd008ary7fw94xyzga40cea6rlqqksq6qk52l549ze48pwenug4pg8g9lrfe3xqsl6dezyxa2a7vtnk83rhhw4uv9h4q4cas9v9r2meqkxmgspwe2r4gxyhn8zu2rraz9xspvj2skkarq30rv58zdqa6a6fftucu8l6788afecfl5r22dta56xfm6ze432hcxupq54sqpsug3dh2a6jqdkpw75pn7kdf60yfj0nru6w920cp808jxch6v3rj04rej26rvyqk5uz90k5kdlrg4c6hdxje2qtueffyw4mjr93yyuq8qjccstrq4qaad77dv42yl3wf5d0pqgceeurf4dtrzey0dt6jtz0tmynmvyzhcqycrcks09wslyy699lufkjcwknxju3t88vh9vffj0xmr5fzsh6cr72mjhwsrelh8lt023xeg0x9zvwn63pgz2es37p5dzlc3kut8sqp2tfy5vpazc58c5u25wg69aqa9vgjxkk94uwugx2n80jhwjqpugpxx9huu297v629hdjchld26c394rydn9t4rckf8ka63q3reelczq9uqdrgjh4azp353rx5x3matwx550cu9kgtwd7jnf76gl67nppkqfqvqqqqqqqqqqqwt6l5ch7kf7lrjfkpz83v2yw4mek6f6www8lwjucqpev25xf2x63tztw2x2mmqpp022yy8faa5csqqz5chxf3fde47ngzntjzhche0lv9ya3ywfagh8qxs490phu0n8pu0pz966d627zse28nap87cn65cpqy370fjf7z03rtrwshkz3fdu3hmknkdcx2sw72yv7elklj780n4qrq3lx7dmmuez3pj84zhhdhvuk9j9cpzxu74hfjkym23dkqya4cqkrtf5xhl06kpnqs6lfahpxjtysyqqwxuqrc", transitions = [{ id = "au1gssvavae6ac53rs8ksw8j9ga3hccp67z28xh36qf4062l8690spsyfy53e", program = "cond_exec_in_finalize.aleo", function = "a", tpk = "769969058670211305403054972674090607838301017799111639698834153018520792433group", tcm = "5925913616768344982910633865433077509444975263571425771517515198551312511915field", scm = "1886094021537141979658158678736082193414687088300410876802743154665441796198field", inputs = [ - { type = "private", id = "7626202372721641535512265492191969309447186797313499247653268394332453807927field", value = "ciphertext1qyq85ue2r3j05nsht40nt5rxeewyzevhu40pl090yfrte5wvw0w3szqhtt7p9" }, - { type = "private", id = "1443812050965843742096133489395435648284251851376088034812367117905213557076field", value = "ciphertext1qyqycthe92m9vq7n2jmqwq6yzrzdlvn3444uel0j6u7g74vyy4nggqc4kmcpq" }, -], outputs = [{ type = "future", id = "8231166181376553910396126064535951686569110152218676702140502043511990822295field", value = """ + { verified = true, status = "accepted", errors = "", warnings = "", execution = { global_state_root = "sr1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gk0xu", proof = "proof1qyqsqqqqqqqqqqqpqqqqqqqqqqqfv98vstq7m3td60zy279n0z85mcg3p7ynssphmyrkceq2depjplfzu7yqv03dte6yjzh2ww79kcypqys9vejps3830l50n6znqk47m7tf00xv4qnpg9vpz4l45rqs7n2hdyxutqjjd6w3j3le0p64u5dpjqw65qva82w874zg2c3sq6h9tyk5dr25rtm4zjfgdvupqd9qjggah5udlr9kuzfz6tpu2zll9sfu92q66ky8vwr6ck4kua08lupcu9ucgaqgsayfag0c2q0uwkzhupe24eyg0pc2c40yv5vfeuvktegkdksql7z3m8z9u0kxajt9fmk0ucze0ljkw4q8pxc4408ug3df68cpqwr0g58tedduc8qf55f9w4xz8r5qqwagg9s8at7dxs46ppzx50sg6slellfutwq9znvgvxwa8k8smpc0gl4d49w886j3n9x053psdg9vsyd9af6rgav390ac4jxdcnzjkhtw97aayrjngj7qrlxng74nxr5re6p6yvfyjnljlgcqrxhpvcc64qrjcqz89jy0sdhj9fm8zlgxczj3hwmpektxwyyhzakeeh0ahakcaa3zjf2f9xqqdndtpxmgfp4fqxqzfcdth7wqx8p50gvmlzc26qflqcsejxvk6y8tktxjlgfl6av99qt5j6dpgn97d69l7elcw8ckeqqpcvhq2cavjhhdqjkr67exzrppn7wyjnr8agn3y86tw7gshxrny5zx7wl5fueu38uuljxmfq7zmkmgr4gz9rurcmmvr0xewchjwtz9crrz4caeel45ejfwztd97kxr2wzfr40avq27jmmyy49vdru5hedfq0zn8ttha5a42vgetvk2e74xr9e3heumr8vtvyqzal6eqsumes5qfpmlnwunu76u6uy8v0p92hpvr3lw5fr98ewp36f633wrwglzqhq9tz97xsy0qw6g4m7qlys0gzrwynh8ak7z8nea24j9jyvhh7n8es9dv87r2jqs4g2mmrx36pfvvcvha2tqws7nsadwr5z5f9vgg40wxzsa8pr6dhrfw8lfh06eukfan0u6pwe02yv38wdt0wme8wg2vpu9q24x93ecassnxhssvrf4j2r7ulpcnpvhaydk0auptyh73f5cr05sda2ga86j96603nsakhdu0lrwrv0dvgqmuzt3yx0ugqcyfh9zxec0qvqqqqqqqqqqqphu7wdzf0j0dyx70svvq40m72sxydjgexchdl3xl9ws3j850wyccu08kjlg5tqm00tknq8p0cknqqqzjjh28ph6mn2jefrq2sfxfc5tjhnegsfj3t47e8n4uu2dwhv2t47ut7vgvg60dm3le92u6y0cxxypq8h6tqt47qnsp8j4sas5mjdwsupc8z0vnfpt8gyzwlz7g2wgd7ms73rk0zracmk4pk2s0vus2g7yplrg04urt3u00xvfjn3mz2u42kpcmqxtlwztvux5ejd22xuql7rfqyqqajgw3f", transitions = [{ id = "au15vf377keldwyq7qgvyayvq3f7fn9f2kjuakk5rs2pyycanw55v8sjzfmzw", program = "cond_exec_in_finalize.aleo", function = "f", tpk = "769969058670211305403054972674090607838301017799111639698834153018520792433group", tcm = "5925913616768344982910633865433077509444975263571425771517515198551312511915field", scm = "1886094021537141979658158678736082193414687088300410876802743154665441796198field", inputs = [ + { type = "private", id = "4299664446792662661158464950597499772199841002875156932750387790879765187593field", value = "ciphertext1qyqzv2elakwejsplxqpmxp4zdmw0dlf59gchuf8pntuy6q6xmmryszgk42pve" }, + { type = "private", id = "2884231031018980721582827513279571048343791047847062842644618255102639163648field", value = "ciphertext1qyqyxs5lwex9kf8rtt9ac854ghl56vhc699fnjp55nxxjdd65rwnurg88ymmq" }, +], outputs = [{ type = "future", id = "2610502413540001155285905690320133801556150626134072679871944001592185929263field", value = """ { program_id: cond_exec_in_finalize.aleo, - function_name: a, + function_name: f, arguments: [ 1u64, 0u64 ] }""" }] }] } }, - { verified = true, status = "accepted", errors = "", warnings = "", execution = { global_state_root = "sr1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gk0xu", proof = "proof1qyqsqqqqqqqqqqqpqqqqqqqqqqqp7fep503nsgv3e5qkwruyp3vftl5k7n9jlsnqpcl6axys04ncvcscpgr36224sapm43zskajkxavpq8yjd3ujv62c6rxrp2l7ggrtmpheze7sq2r485pptz6pq8zynvkcxn8ywqvn74fdpgyrpe3gf9t6sq9f55daenaytwgy6ftfkkx77hvwrn8te5uylhj78a4nq5hsd32yqhthe4rmzm26ma72wk2a2q7xfxqe832ksstasa3kg0m2zgetexkeglcgav7qkdn6zz63gdv47h97qk7ct3nma9k0gnfg4ny4fzu8gecp9e4nurpw7ewjve47el4ecv0flkar25qv5fexucpr4nu08za2cxfjpj9aaer2q4q9u8cnr6gxnkxgpg73dlf3r5nx9xmm47jgkpee0qz593uktpqm49mxc35et02ttqj5ph3m0p530as3arurrcztwmvaqzrwagcl5tl0h665rvc4kw9k2dkdyyx2lpf4n07uy2dr3gcje35gfg6cyccpkg4h7z78std0gadrqqfs7vvh9atg6ktwfpdphxqv0xdrm673lc25xt8wvnanxa8r9cgr9atun00fxjswht0urd8ynugzq5q5e9lsklcyuprfgtuvygrlasyx64ssv4l280y32csexn0ayk6rrzuuxx46swh3g9fxkcrzr3h92jvqcj32fvgc8lquk3fh7axc49sya3kazy8vsyw5yp6dezt2hwegzyq4rk02hg8ktqkpudt7wa5e6mu42nv8wnaznasa5tc7j2kfvncacqtnqzhze9ayycn0ceq8ppvs857regmyptuwg6yvtfl70cjm5v98z8jzhwfpaq94ggsmvd3pzpjyexz6ref7z63wnay8904j0a00m0nqdl58ekcnssp3dh6hcfat80nctkk08ztqnpktdlrxrryht8lndzsgdn285le7nus67yul0jq49uu7uy0cmzdz2pla032mnc5a9heakgya535quswnhrav8vsumttp2ecy5yadzjn40mjngk4wlhhnmccq7zeyfkqv2gzhk2znsh0h7r6vskpkk8srn7kl98ydv0l9yn9mnqa6zzrjd5jtw84myemrk0ttus5ywy2s2a4vh09yvsj96574tzk2awks4fftxd4uw8366e0y3pmhfa2zzjuhvxh4eys3fan8k9rdy3t9usszqvqqqqqqqqqqpzvsxu0tdxk387x2wwxv4dftmauj0zhexhrdw7lncu54z0kk0z8yzmraem3wn4y4jquy838f67c6sqqpkjnfuhpspq9wnv6gql0w829p6s2r75avzlngaaxetazlqmu3qhwch2adaqlh3tg8gy7mwv7ts6yqq8u7as4t2sxdtc48knt7yhwgqte35swwzg9zzrvwdwp9hyw4jv9pykz9gfw4ng9flsl625vu6ekupg95gpvzvkmtwpz7k9njyn5pz5cgcx2atd5weh4ks2tsvsxz6fy3qqqq8lc238", transitions = [{ id = "au15g2dzv539esrh62fvcy5vsddkfyrzzk7nnepmzlqfpyv22hn5qxqtnpn6q", program = "cond_exec_in_finalize.aleo", function = "a", tpk = "3944001539338773920385360533696508669316623780459830039129651343406354973968group", tcm = "5854238226448648076159184366434581922193197117627936839271893386087664253575field", scm = "739276317952343341616529172088594290231100072446409874714908969030318369312field", inputs = [ - { type = "private", id = "5755235326889702063396661360406534619980588488304068553623334414887009409776field", value = "ciphertext1qyqps4a7t45ykg473tu3nt59q5rll0jrq3ghy5y70dfcvgq9kqf7zpchzxdwx" }, - { type = "private", id = "3168774907191969896146509716630837060431141939375351609835731626544876393367field", value = "ciphertext1qyqx5j5cmspsnncytmhu27m677ncd6k998h2sk9pqfe6q7kdnjalzqs5h2ltw" }, -], outputs = [{ type = "future", id = "8003027955445173917787103564419705677737189877194407988894713228635015061036field", value = """ + { verified = true, status = "accepted", errors = "", warnings = "", execution = { global_state_root = "sr1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gk0xu", proof = "proof1qyqsqqqqqqqqqqqpqqqqqqqqqqqqupq64s26tz3f5snj59j6wn2u648mtmxeqss0yrx7r76fmvl827c7agf7fet3q5vmnyxe9wafkpgpq8yjd3ujv62c6rxrp2l7ggrtmpheze7sq2r485pptz6pq8zynvkcxn8ywqvn74fdpgyrpe3gf9t6sq9xu48a59hrg8m5pj7agfr5zemtl9293204lq822wtpetcx5zsm20a4en5yprg5tlv90p5wqskaskqa55m33dm46ty7qr43aakm38mwj8l35r4vkknncrqn55c4496m0s338cd5f5cea3jcn2ukeyk6mpsqzlgew3mjskcfqa9capnuzdrh3tqylv3f3sd7an9afk50zfldvf5tw6ypczfrmzl3gucdh6ylc0fgp5zp2ffpz9va3dut9kzyyg3pyjky94w4vm93wvsczmjpg2kvu46eczetpedl6j3hmd4dw6hnaxrmqyh8cqmxvj5270y9qcks32avgfasgq6042gqnxf7chm6ujy2w893lu4w32djh0l3twppe8sk6w8chqf6dmzmg27nqsjw72swkfl7x8vc6nx5vtaas2tapnwnr5u4vw7r4j5uja8x635ku9sk83hpdyx666qqe94qyszytffau77cec6k8sjd3utgj03rety20wp3hfkmme5wcf373j82exl3ggfemnus53r29suqzt20yphl5r48qee7kcl8vt7ache2dcalfeu6v8q2ktdwq4un0s9akcuu4adznk526yanupmyw0t0lp0eyf662yk0k2pes7xdk3uvyrnjwmfxpepacsdnl74tl49rw2wawdsnagmfwh5e440fsvfkj5m6q4tkdn3gxx9ty7p7dhee9afxpry7gyxqjspcw044r953q4rqrkjq0n2emg2el6xj7ruu8ff9dz5tarq39lvr2vs80wdears6u49dp8s8squ93p7jxp54grrrp07jd4lsgrlc8vs0h5r3ph03upewn38qeg898vlj5939j4f6sqg2w5t8kx35mm3qplucu92q0n5hy68s40llwyfe8jz5ksyzme8hclu3pyt8v5d0apnfkhls06wedq7qemkmwgkzph5436c8q4luplerpvn6s568enm9e68w20pxqpkke5a2uxml6czq4zrlrcpk9q7f4cuh6xjn5xummx9l5fx82zz2hlak20n4g667p7qyqvqqqqqqqqqqqclftsqqpm8rk83dzpj4v5re6cpl6q07avz4kz490a7wdek0wyexf69fhwn73z3tlelsd9mud86xsqqg3lanzpsukh4a6m4xe6fnahv8y00y8c8nfzvgf0754ck3tjgpd4n96hfu3jr4m8s04lh3ex4fkhqpqyjaymz9ju05gzqtkz7jn3trr50eznkfrwwtyhm24htq60wpksqppnkumhtgmtp948rtgg7pjmpevynxdtvwh432zjp4mwwxhpl6s0p4chk5g5rqeneppxd9ykmykyl6qqqq32w3yq", transitions = [{ id = "au1uj00an5rmvwytpqff0dnquukp88hyt3rwwytsq72y5y3zyxklsxsrxn8tl", program = "cond_exec_in_finalize.aleo", function = "f", tpk = "3944001539338773920385360533696508669316623780459830039129651343406354973968group", tcm = "5854238226448648076159184366434581922193197117627936839271893386087664253575field", scm = "739276317952343341616529172088594290231100072446409874714908969030318369312field", inputs = [ + { type = "private", id = "6315801367787184026400925842650436940616535740179175878123170015770272480113field", value = "ciphertext1qyqt3m98vv79t7v8vnjjc930x9k7ufzsnj7urwqjk88qe4gs4yt7jpckfma7f" }, + { type = "private", id = "955221417850357928618980243600906761142592144048548546041180972541781149338field", value = "ciphertext1qyqf08kzj4cew5xgt3tmejfx34qcmtyvp27ha7ep9lged2p5er64kqqzgmwzg" }, +], outputs = [{ type = "future", id = "8130559431578912767460207086477675334231317222766323262703045699603185538233field", value = """ { program_id: cond_exec_in_finalize.aleo, - function_name: a, + function_name: f, arguments: [ 1u64, 1u64 ] }""" }] }] } }, - { verified = true, status = "rejected", errors = "", warnings = "", execution = { global_state_root = "sr1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gk0xu", proof = "proof1qyqsqqqqqqqqqqqpqqqqqqqqqqqrtyt3hwgzfjty9h0cxu2fwg3typpxljhale6zs74aqscrdjj9tc8n9q7pchkh94fs53hturft6jcqq9e92wq22mlgss986end2hhrlsa9404fujm4tsga5ezn8053hsvhw8cnvkpzppkat2cwm326cmx87qrydjh6xk644j0njkm5dvhhujwntzup9z7yj4ndn6pegdpjmh7a0t60wq7c0nw5t5aksswuwk3vevq8mlg2yv0m3q6a52vr2n7ygw6uakwtcknyz4d6p8y0wuue8qzyzzmdaystcy09e3cch4qf4gpxndsqf733dhx6jne7aul3qwxvt5y9jp6v44fwtxn9yyw56l6sxwrzvwn8n48jlp5h2qj44qqapr5yvqmqq2k097uh636y2g9h6s7wf4zgljvdfgl2qsnpduxw6sz64dprmdp2wk3t6np82mkn2uz7euurfllrsqdjyvhlv5ger9696rrc7xuwgsrlctgpk6fgmgrh44drw529hwmqhyd4wamuakuxr32xtrjgv3980qrfq0l4f5sej7aru9m3x3aczppdh74n2u2xx2gth0lf9zce07v55sl3mdpm9ealjprzjq6fztpphzqfnr65ht63u8s0a3rl6z3yh380pk60t0p380g2z0zgj5k6gk8k0xd234rx33pe4n7hr6r3zulyl3gqc4d4vmz0fuexkh2c9fwl2ak2wnlafv42utzr5q3u4cq079fyz5gjtumex0ltq7697agtfpa85wewj84rxsuwf5z25c7227h5ea382rs06n5wh3xqnshfydq8pzwt2xvnxsaz4uj80w6u8cdxdjwswxv8pv6teqjggu5h2n49tx55kvxgyzu356py0hfefd7g9f3krg8drxtqzurhkx0adaaj8ka242fnqkzlvl6e3839mmyedgu6s2muj22yywsdwvfqke3lj4hsy39lgazpg0cjxugyep7hekzd3wpfe87weqtl8vq4c253fav24uf5fkvwd7zc6a3qsjtfytztaz294u03tyxhewk4wyd4qz92zakhquy9f3gfgnhfflwc8jqws24rxsjjg9pvk2xug2x8p6mrm8prhp29mzj8vu2q2cqldc92ktv9mjwrpmnwsq9jx5ssk6tqwpsu6w5dpxyswvg4pmqq3p7u62qrwy7my9x5cnu6pn6y62fapdcrqvqqqqqqqqqqp55zmveuwjxlk9qpr83mpnyes38hh0vckeaaqff2p8ad254z3sxn3g99whc5q8gvncdce6n7dh00qqqfqyhx8660fypkg4d9shhgplsvec4q46k8kekc3vc8wcy86q57uygy988mxwwtvfaj2lf2jeeyuzcpq8qwltgqw4thlzvrsuqpgckqc3w9cjkfkshwucedjdvc5l0u9d6pygyt5uxjcmgx6hy7z4xnx6jd7e7zd9xheemd0496qtnanjj94mxc5elxvs7wk9t7h3spast3ymq7qqqq60ahha", transitions = [{ id = "au1vm9z2lj66auhxnttt6ttmvkcls4n33pnw5luytxf7q5sugz2mg9s2mnxpk", program = "cond_exec_in_finalize.aleo", function = "a", tpk = "6497893695285924190886988099286850340592111983422894045205456561953781042463group", tcm = "5356618385916014026788680411791041563447120696363074218812093120828036880964field", scm = "6394314791324076323128735909574169416822398762092026258451607675413037400008field", inputs = [ - { type = "private", id = "6198652585657260926426509444997868163964918416464849417615079714896319348277field", value = "ciphertext1qyqywze23n5d4hwjyrv8wj4wqtdf6qh9s8v53xczpnsd37werv9kuzg9wph3y" }, - { type = "private", id = "8382351396873690135158297135263023868922664846333758390492559925774475695943field", value = "ciphertext1qyqzxypstrnl4lm63lzqfmwn3d988rvu3rr8qkklykxlvv3dupp0vyqy7j0tj" }, -], outputs = [{ type = "future", id = "7667170962147625602914227675444707942639000179432959786181658614205536097569field", value = """ + { verified = true, status = "rejected", errors = "", warnings = "", execution = { global_state_root = "sr1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gk0xu", proof = "proof1qyqsqqqqqqqqqqqpqqqqqqqqqqq0t7x8cj6n6wx29zzt3xkeutfw6evcc0pzyd5k6c5fsvakvgv9ayyn2vgv3tl79vzrc5n66lm76jqqq9e92wq22mlgss986end2hhrlsa9404fujm4tsga5ezn8053hsvhw8cnvkpzppkat2cwm326cmx87qqv286wxss0kuxxed4x4yh7cjm8ddwzxc7utv924n7ghyj7l59dt70ywgy5qc7tknkgvtkg53mdx5qnpkq6e4nenedvz4yhzder54hp47946rr7l9ee32jmtqj8j09ghd5jle3awl8t5rvz8p78gmu92v5q6t38450h8qyedylrqs7ace25slphsar93x6xlsgz4lfq6d0mjd95fwqfgfknndh49ac7pvhs8c0cpa52ewusl7pvntr2k892l5wa59t99yzzuzj3txlx90r8us40rc7097uspyuetvckfnn6rpkxwqd9sx3l2uwjul2uex6ut9krdregrh6jds7ne3vpmnpplf7n8c8qpyalp7kch64uuv4lzdypqs86z2mjyqwaqeh74pl9dnmclk2c0jjff5fmwyvkkgjs369yeu9f2yf2vjkrv83x7dgnnckw2h37k3e72gwwg6q0ufdtf6yklkccehwce74zx9pau2489erec23w3j6lcku95svmt0j5x4el6lhwrxcg2wr5cxkq6ryqhpjzgtmxcjuyt3cg0yx9vn5xx8jee70ee7m7n4rqa3p58vvcaqxrujymynpedju95ff4kml5vxqyrfqu4lyfn45djp2r5ql507k2uz6qnkwy5zuw7aljsx4vl0edavan9haaphh8tzhvz2y4jn36ly6hqt28g74k5pqq5h299lsl4k4n5dt3wdanuju6vrzakqyej5r7z6zqfl39quyyt9nysccgldg30x9am7sh3vqqv795y7zuu7pe2e6lr0g8sphlpp0uq5t7naqgjmqgmemlcl32ds2858m2a8dxvkra804adqqk7nsd6jwjxujxmh937v86s38ddatw634tejpc3zfg8gy3hpu6crtn2fsmr9y8kksvndwkn07qef80jrdepan5aqqrtfycfa9cy5e5puu6u4evr8jx93aj5vk35n8dslz7la7h00g8vsl3wqsqqrtjty5qexrdhtyhm47ah3wdj2gnusfezgrlq7gt5f3at9ae98fvn6yeu4ssqvqqqqqqqqqqq7089yqgq7ze0lfj9s3gl2nqkjxlfezg3fe8chz8pevzxyw3u0adfhaag50u38slvfw8fjkhw9uysyqznhjy34zu4jcrgduyvxzcce4k9ptlkde2nnp7rx9ze0u5gay80twx3ag4zg0uwfk5w97mcj6mmgcpq92jsj4fxwvmg9c0dlnvqaq59h23ccdyx9zuqd3hmmdn5uklrrxs4l5hupz6mpdqcj705faytg550gqe6lzes7eryhy4k366j8smt062nmp2redcakd4sdkqly4klha6sqqqt36mn8", transitions = [{ id = "au1kfmlhlt6dsdcjenn93vxr78g5ws9mccnwrctl0u0vsr9wq4qlugs2j9cl9", program = "cond_exec_in_finalize.aleo", function = "f", tpk = "6497893695285924190886988099286850340592111983422894045205456561953781042463group", tcm = "5356618385916014026788680411791041563447120696363074218812093120828036880964field", scm = "6394314791324076323128735909574169416822398762092026258451607675413037400008field", inputs = [ + { type = "private", id = "1920405931972337968797623575143929359913310014681402441055994736648259622107field", value = "ciphertext1qyqd7gqtp6rnjq59j4nlnmswf853tfq2un0n5cnewkd9kaaqa9k6jqcwtgzcv" }, + { type = "private", id = "5620689933767446073900947735330872718147981878103725711953362219835218051225field", value = "ciphertext1qyqyp7vkv4f65ceaezw6vzwagjupn2x70hptwmcvhq60we7c8dmlcpqxudz5u" }, +], outputs = [{ type = "future", id = "718348516900992946757003232006344847115215417917880511938054443988358753927field", value = """ { program_id: cond_exec_in_finalize.aleo, - function_name: a, + function_name: f, arguments: [ 1u64, 2u64 diff --git a/tests/tests/compiler/function/transition_calls_async_function_fail.leo b/tests/tests/compiler/function/transition_calls_async_function_fail.leo index 63ad677572..e5a143a28d 100644 --- a/tests/tests/compiler/function/transition_calls_async_function_fail.leo +++ b/tests/tests/compiler/function/transition_calls_async_function_fail.leo @@ -5,7 +5,7 @@ expectation = "Fail" program test.aleo { - transition a(a: u64, b: u64) -> Future { + transition f(a: u64, b: u64) -> Future { return finish(a, b); } diff --git a/tests/tests/compiler/function/variable_shadow_function_fail.leo b/tests/tests/compiler/function/variable_shadow_function_fail.leo new file mode 100644 index 0000000000..61a32178d6 --- /dev/null +++ b/tests/tests/compiler/function/variable_shadow_function_fail.leo @@ -0,0 +1,15 @@ +/* +namespace = "Compile" +expectation = "Fail" +*/ + +program test.aleo { + function f1(a: u8) -> u8 { + return a * 100u8; + } + + transition main(id_type: i8, s: u8) -> u8 { + let f1: u8 = 1u8; + return f1; + } +} diff --git a/tests/tests/compiler/mappings/variable_shadow_mapping_fail.leo b/tests/tests/compiler/mappings/variable_shadow_mapping_fail.leo new file mode 100644 index 0000000000..8051bc3be3 --- /dev/null +++ b/tests/tests/compiler/mappings/variable_shadow_mapping_fail.leo @@ -0,0 +1,13 @@ +/* +namespace = "Compile" +expectation = "Fail" +*/ + +program test.aleo { + mapping m: u8 => u8; + + transition main(id_type: i8, s: u8) -> u8 { + let m: u8 = 1u8; + return m; + } +} diff --git a/tests/tests/compiler/statements/expr_statement_fail.leo b/tests/tests/compiler/statements/expr_statement_fail.leo index 6700970a52..68266dfea9 100644 --- a/tests/tests/compiler/statements/expr_statement_fail.leo +++ b/tests/tests/compiler/statements/expr_statement_fail.leo @@ -9,7 +9,7 @@ program test.aleo { a: u8, } - transition foo(flag: bool, a: u8, b: u8, foo: Foo, i: i8) -> u8 { + transition foo2(flag: bool, a: u8, b: u8, foo: Foo, i: i8) -> u8 { a + b; flag ? a : b; foo.a; diff --git a/tests/tests/execution/cond_exec_in_finalize.leo b/tests/tests/execution/cond_exec_in_finalize.leo index 1ff151c3ad..ab384077fb 100644 --- a/tests/tests/execution/cond_exec_in_finalize.leo +++ b/tests/tests/execution/cond_exec_in_finalize.leo @@ -3,22 +3,22 @@ namespace = "Execute" expectation = "Pass" [[cases]] program = "cond_exec_in_finalize.aleo" -function = "a" +function = "f" input = ["1u64", "0u64"] [[cases]] program = "cond_exec_in_finalize.aleo" -function = "a" +function = "f" input = ["1u64", "1u64"] [[cases]] program = "cond_exec_in_finalize.aleo" -function = "a" +function = "f" input = ["1u64", "2u64"] */ program cond_exec_in_finalize.aleo { - async transition a(a: u64, b: u64) -> Future { + async transition f(a: u64, b: u64) -> Future { return finish(a, b); }