From 440ad0847f94587604dee6d6c86b91bade5f9656 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Wed, 19 Jun 2024 15:31:45 +0000 Subject: [PATCH 1/3] fix: update `in_contract` flag before handling function metadata in elaborator --- compiler/noirc_frontend/src/elaborator/mod.rs | 1 + .../compile_success_contract/recursive_method/Nargo.toml | 6 ++++++ .../compile_success_contract/recursive_method/src/main.nr | 6 ++++++ 3 files changed, 13 insertions(+) create mode 100644 test_programs/compile_success_contract/recursive_method/Nargo.toml create mode 100644 test_programs/compile_success_contract/recursive_method/src/main.nr diff --git a/compiler/noirc_frontend/src/elaborator/mod.rs b/compiler/noirc_frontend/src/elaborator/mod.rs index 91d6ba71927..f4ed0b6912b 100644 --- a/compiler/noirc_frontend/src/elaborator/mod.rs +++ b/compiler/noirc_frontend/src/elaborator/mod.rs @@ -1302,6 +1302,7 @@ impl<'context> Elaborator<'context> { for (local_module, id, func) in &mut function_set.functions { self.local_module = *local_module; + self.in_contract = self.module_id().module(&self.def_maps).is_contract; self.recover_generics(|this| { this.define_function_meta(func, *id, false); }); diff --git a/test_programs/compile_success_contract/recursive_method/Nargo.toml b/test_programs/compile_success_contract/recursive_method/Nargo.toml new file mode 100644 index 00000000000..8142e5b3278 --- /dev/null +++ b/test_programs/compile_success_contract/recursive_method/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "recursive_method" +type = "contract" +authors = [""] + +[dependencies] diff --git a/test_programs/compile_success_contract/recursive_method/src/main.nr b/test_programs/compile_success_contract/recursive_method/src/main.nr new file mode 100644 index 00000000000..6fd4bf3338d --- /dev/null +++ b/test_programs/compile_success_contract/recursive_method/src/main.nr @@ -0,0 +1,6 @@ +contract Foo { + #[recursive] + fn contract_entrypoint() -> pub Field { + 1 + } +} From e5158bee87bc48c7175ad457b89d017a20a47167 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Wed, 19 Jun 2024 15:45:49 +0000 Subject: [PATCH 2/3] chore: clippy --- compiler/noirc_frontend/src/elaborator/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/noirc_frontend/src/elaborator/mod.rs b/compiler/noirc_frontend/src/elaborator/mod.rs index f4ed0b6912b..ef5f961148f 100644 --- a/compiler/noirc_frontend/src/elaborator/mod.rs +++ b/compiler/noirc_frontend/src/elaborator/mod.rs @@ -1302,7 +1302,7 @@ impl<'context> Elaborator<'context> { for (local_module, id, func) in &mut function_set.functions { self.local_module = *local_module; - self.in_contract = self.module_id().module(&self.def_maps).is_contract; + self.in_contract = self.module_id().module(self.def_maps).is_contract; self.recover_generics(|this| { this.define_function_meta(func, *id, false); }); From 3fad9cffaf469012a51d32b1ec8fd53ef1af7c40 Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 20 Jun 2024 15:13:17 +0100 Subject: [PATCH 3/3] fix: restore `self.in_constract` after defining function meta --- compiler/noirc_frontend/src/elaborator/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/noirc_frontend/src/elaborator/mod.rs b/compiler/noirc_frontend/src/elaborator/mod.rs index ef5f961148f..dc99ceae2f0 100644 --- a/compiler/noirc_frontend/src/elaborator/mod.rs +++ b/compiler/noirc_frontend/src/elaborator/mod.rs @@ -1302,10 +1302,12 @@ impl<'context> Elaborator<'context> { for (local_module, id, func) in &mut function_set.functions { self.local_module = *local_module; + let was_in_contract = self.in_contract; self.in_contract = self.module_id().module(self.def_maps).is_contract; self.recover_generics(|this| { this.define_function_meta(func, *id, false); }); + self.in_contract = was_in_contract; } }