When will it be possible to use operators with custom defined types

Looking to convert existing repos to PRB math v3 however since these contracts contain large equations, having to use 25 mul() functions per line or having to wrap and unwrap just to multiply two variables will result in illegible code.

Just wondering when this will be possible. There was a video on youtube posted 8 months ago stating that this was in the works.


contract type_test {
    type UD is uint256;
    using {add as +, mul as *} for UD global;

    function test(UD x, UD y) public returns (UD) {
        return x * y;

Here’s the roadmap task you can watch to track progress: User defined operators/literals #13718.

Basically, operators are already implemented and waiting to be reviewed. Here’s a comment explaining in detail what was implemented in the end (feedback is welcome). If there are no major change requests in review, it’s possible that the PR will be merged in time for the next release, which is planned for mid-January.

The feature as originally planned also includes support for literal suffixes. Suffixes are meant to provide an easy way to construct instances of user-defined value types from literals since custom operators will work only with those types. These will be ready soon but at the moment they’re still not finished, so whether they can make it into the release depends on when exactly the release happens.

1 Like