Skip to content
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

Merged
merged 10 commits into from
Jul 26, 2022
Merged

Conversation

tserg
Copy link
Collaborator

@tserg tserg commented Jul 22, 2022

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

Put a link to a cute animal picture inside the parenthesis-->

@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2022

Codecov Report

Merging #2977 (6a7dbc4) into master (dbcc9c7) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@            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     
Impacted Files Coverage Δ
vyper/builtin_functions/convert.py 91.03% <100.00%> (+0.43%) ⬆️
vyper/codegen/types/types.py 88.88% <100.00%> (+0.14%) ⬆️
vyper/utils.py 84.68% <0.00%> (-5.16%) ⬇️
vyper/builtin_functions/functions.py 90.25% <0.00%> (-0.72%) ⬇️
vyper/codegen/ir_node.py 91.69% <0.00%> (-0.70%) ⬇️
vyper/ast/expansion.py 93.93% <0.00%> (-0.18%) ⬇️
vyper/ast/folding.py 91.59% <0.00%> (-0.14%) ⬇️
vyper/codegen/core.py 84.99% <0.00%> (+0.08%) ⬆️
vyper/ir/compile_ir.py 93.70% <0.00%> (+0.22%) ⬆️
vyper/ast/nodes.py 93.17% <0.00%> (+0.33%) ⬆️
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

@tserg tserg marked this pull request as ready for review July 23, 2022 16:48
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.
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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

Copy link
Member

@charles-cooper charles-cooper left a 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

tests/parser/functions/test_convert.py Outdated Show resolved Hide resolved
vyper/builtin_functions/convert.py Outdated Show resolved Hide resolved
vyper/builtin_functions/convert.py Outdated Show resolved Hide resolved
vyper/builtin_functions/convert.py Outdated Show resolved Hide resolved
@charles-cooper charles-cooper enabled auto-merge (squash) July 26, 2022 11:39
@charles-cooper charles-cooper merged commit 7b8b082 into vyperlang:master Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants