fix: correctly solve paths and generics in trait default methods
Description
Problem
Resolves #8632
Summary
This PR implements a workaround for solving #8632. The correct solution would be the one described in https://github.com/noir-lang/noir/issues/9020 but, as noted there, it's not trivial to do so. But this workaround would unblock users that use trait default methods (which, I think, is a very useful feature).
There are two workarounds here:
- Because the trait default method is copied to the trait impl, if the default method refers to a type or function by path, that path was incorrectly looked up starting from the trait impl's module, not from the trait module. For this, default methods copied into trait impls will now have a
path_resolution_moduleset, which will be set in the Elaborator so it uses that module for path resolution. - The next issue was that if a trait default method refers to a trait generic, that generic no longer exists in the trait impl as it's been substituted by a concrete type. To solve this, we define these generics with solved typed when defining the copied trait method.
Once #9020 is implemented (could be after 1.0) we can undo these workarounds.
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 and/or
cargo fmton default settings.
Not sure about implementing a workaround when I'm also unsure how difficult the full fix would be. I'd like to take another stab at https://github.com/noir-lang/noir/issues/8797 which could maybe open us up to a different implementation of this where we elaborate once on the trait and use that instead of copying beforehand.