-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement Operator Overloading (#3931)
# Description ## Problem\* Working towards #2568 ## Summary\* This PR implements operator overloading through traits. This works for all operators in noir, including bitwise operators. The comparison operators `<`, `<=`, `>`, and `>=`, are notable in that their corresponding function `cmp` returns an `Ordering` object rather than a boolean as the operators themselves do. ## Additional Context There is a bug when using static trait function syntax `Default::default` or operator overloading when the trait has generic methods. I'm considering this a separate bug, although for the moment it prevents us from being able to use e.g. the `Eq` trait for arrays. There is a boolean in `type_check/expr.rs` that determines if we use a trait impl or primitive implementation of each operator and because of this bug I've kept the primitive implementations for string and array equality. ## Documentation\* Check one: - [ ] No documentation needed. - [x] Documentation included in this PR. - [ ] **[Exceptional Case]** 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: Tom French <tom@tomfren.ch> Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
- Loading branch information
1 parent
459700c
commit 4b16090
Showing
30 changed files
with
1,219 additions
and
328 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.
4b16090
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://noir-lang.org as production
🚀 Deployed on https://6595b225ada86b050209a29a--noir-docs.netlify.app