-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(frontend): Error for when impl is stricter than trait (#5343)
# Description ## Problem\* Resolves #5210 ## Summary\* For context it is good to start with the linked issue and the discussion. In the linked issue discussion, a non-existent trait implementation would pass type checking and fail during monomorphization. It turns out the linked issue's error was not that the compiler should error with `No impl found ...` but rather that the impl has stricter requirements than the trait. When we move the `where` clause to the trait impl we get the expected no matching impl error as expected. But now the following code from the issue will have this error: <img width="744" alt="Screenshot 2024-06-26 at 4 30 39 PM" src="https://github.com/noir-lang/noir/assets/43554004/63b3cb45-91d0-4bdd-abc2-e9ba97c541a8"> We will also error if the object type in a trait constraint has different generics: ```rust trait MyTrait { } trait Bar<T> { fn bar<U>() where Option<T>: MyTrait; } impl<A> Bar<A> for () { fn bar<B>() where Option<B>: MyTrait {} } ``` Will return the following error: <img width="764" alt="Screenshot 2024-07-10 at 4 57 22 PM" src="https://github.com/noir-lang/noir/assets/43554004/98489dc8-72aa-40ec-9b82-e56555affebd"> I have also attached a test showing how we get the expected no impl found error when the where clause is accurately placed on the trait impl rather than the trait impl method. ## Additional Context The way we attach trait impl where clauses onto methods did complicate things a little. We should consider maintaining a clearer separation for where clauses on impls and where clauses on functions. ## 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. --------- Co-authored-by: jfecher <jake@aztecprotocol.com>
- Loading branch information
Showing
14 changed files
with
616 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.