-
-
Notifications
You must be signed in to change notification settings - Fork 791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement flags semantics for enum #2915
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2915 +/- ##
==========================================
+ Coverage 88.30% 88.35% +0.04%
==========================================
Files 96 97 +1
Lines 10611 10663 +52
Branches 2531 2540 +9
==========================================
+ Hits 9370 9421 +51
- Misses 787 791 +4
+ Partials 454 451 -3
Continue to review full report at Codecov.
|
test: tests for enum flags
…into enum_flags
Enum flags - more tests and docs
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.
Would need to see some more tests about storing and manipulating stored values e.g.:
@external
def addMinter(minter: address):
assert self.roles[msg.sender] in Roles.ADMIN
self.roles[minter] |= Roles.MINTER
nice catch, see 4efa50a |
oh shoot -- i forgot to tag @tserg in the commit message. he wrote a significant portion of the tests for this PR, wrote the docs, and helped update the grammar for the new ops. |
implement operators so that enums can be used like Python's `enum.Flag` ("Base class for creating enumerated constants that can be combined using the bitwise operations without losing their Flag membership"). this also enables bitwise and/or operators for uint256, and deprecates the builtins `bitwise_and` and `bitwise_or` this commit also adds clampers for enums - an enum must be in bound for the number of members the enum has (and also, any enum runtime value must be nonzero). Co-authored-by: tserg <8017125+tserg@users.noreply.github.com>
What I did
implement operators so that enums can be used like https://docs.python.org/3/library/enum.html#enum.Flag ("Base class for creating enumerated constants that can be combined using the bitwise operations without losing their Flag membership").
This also enables bitwise and/or operators for uint256.
How I did it
Add BITAND, BITOR to the syntax. Implement codegen for
&
,|
. Add clampers for enums - an enum must be in bound for the # of members the enum has (and also nonzero).How to verify it
see tests, also check compilation of the following test file
Commit message
Description for the changelog
add flags semantics for enums
Cute Animal Picture