Skip to content

Commit

Permalink
fix: update in_contract flag before handling function metadata in e…
Browse files Browse the repository at this point in the history
…laborator (noir-lang#5292)

…

# Description

## Problem\*

Resolves noir-lang#5288 

## Summary\*

This PR fixes noir-lang#5288 by updating `self.in_contract` before we define
function metadata to match `self.local_module`. This is mildly hacky and
we may want to have a nicer "switch modules and update everything which
depends on it" helper function in future.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Jun 20, 2024
1 parent 91a9b72 commit 4c4ea2d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,9 +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;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "recursive_method"
type = "contract"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
contract Foo {
#[recursive]
fn contract_entrypoint() -> pub Field {
1
}
}

0 comments on commit 4c4ea2d

Please sign in to comment.