Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: let trait calls work in globals (noir-lang#5602)
# Description ## Problem Resolves noir-lang#5029 ## Summary Trait constraints weren't checked after elaborating a global. ## Additional Context I couldn't just call `check_and_pop_function_context()` because that also defaults type variables... and if we do that the usage of a global will not have an effect on its type. I guess this is one scenario: ```rust global x = 1; // What's the type of x? ``` We don't know. I guess it ends up being `Field` later on (where?) But if we have this: ```rust global x = 1; fn main() { let y: i32 = 0; assert_eq(x, y); } ``` now x's type will be `i32` because of that comparison. So if we eagerly bind `1` to its default type, this will break. All of this to say: in Rust a global's type (well, for a `const`) must be explicitly specified. I guess that if we also did that in Noir then this wouldn't be a problem. And given that globals are, well, global, it might be strange to have `global x = 1` expecting that to be a Field, used as a Field in many places, but you accidentally compare it to an `i32` and the type changes under the hood. But that's a bigger discussion, so maybe the fix in this PR is good for now? ## 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