We’re aiming to release solc 0.8.18 somewhere next week and one of the major new features will be the support for user-defined operators. We usually only get feedback on features after they are released so I thought I’d try something different for a change. Below are the links to the dev binaries from our CI with the feature implemented. Feel free to try them out (version 0.8.18-ci.2023.1.17+commit.e7b959af
):
You can read a detailed description of how the feature works. It’s up to date except for one thing that was changed after it was written: operators can now only be implemented with a pure
function.
I invite everyone to try them out and comment on what you like or dislike about the current design and implementation. Here are some questions that I’d be particularly interested in but any feedback is welcome.
- Should we allow using non-pure functions for operators?
- Given current limitations, do you think operators on structs would still be useful?
-
!
returns the same type it takes rather thanbool
. Should it be returningbool
instead? - Are the error messages clear and detailed enough?
UPDATE 2023-02-09
Here’s a new preview (version 0.8.19-ci.2023.2.8+commit.0cf7cd30
):
Changes:
- It’s no longer possible to define
<<
,>>
,**
and!
- Operator definition must be a free function. Library functions (especially external ones) are no longer allowed.
- Operator definitions must be global. It’s not possible to define an operator in contract scope or for UDVTs defined in contract scope.
- Multiple conflicting definitions are detected immediately in
using for
rather than when the operator is actually used. - SMTChecker now warns that user-defined operators are not yet properly supported.