-
-
Notifications
You must be signed in to change notification settings - Fork 788
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
feat: add convert for enum #2977
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2977 +/- ##
==========================================
- Coverage 88.16% 88.12% -0.04%
==========================================
Files 97 97
Lines 10820 10894 +74
Branches 2569 2580 +11
==========================================
+ Hits 9539 9600 +61
- Misses 823 838 +15
+ Partials 458 456 -2
Help us with your feedback. Take ten seconds to tell us how you rate us. |
docs/types.rst
Outdated
@@ -622,5 +622,6 @@ All type conversions in Vyper must be made explicitly using the built-in ``conve | |||
* Narrowing conversions (e.g., ``int256 -> int128``) check that the input is in bounds for the output type. | |||
* Converting between bytes and int types results in sign-extension if the output type is signed. For instance, converting ``0xff`` (``bytes1``) to ``int8`` returns ``-1``. | |||
* Converting between bytes and int types which have different sizes follows the rule of going through the closest integer type, first. For instance, ``bytes1 -> int16`` is like ``bytes1 -> int8 -> int16`` (signextend, then widen). ``uint8 -> bytes20`` is like ``uint8 -> uint160 -> bytes20`` (rotate left 12 bytes). | |||
* Enums can be converted to ``uint256`` only. |
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.
What are the issues to converting to lesser values? Can't you determine the upper bound for a given Enum and throw a compiler or runtime error if it exceeds it?
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.
Since enums are uint256
under the hood, I don't think there are any issues with supporting conversion to smaller integer types. It is more of whether we want to support that conversion.
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.
@fubuloubu i think the whole range of ints is a bit harder to test; we can add them later too
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.
i think we should have an int to enum
rule as well
What I did
WIP
How I did it
WIP
How to verify it
Commit message
Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)
Description for the changelog
Cute Animal Picture