-
-
Notifications
You must be signed in to change notification settings - Fork 828
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
Cannot declare HashMap inside struct #2316
Comments
This is a documented behavior. Including a mapping within a struct means the struct cannot be used in calldata or memory, and so creates an inconsistent behavior dependent upon the shape of the struct. |
Seems like a better approach here would be a simple Better support for Enums would make this easier (similar to enum Roles:
admin # bit 0
... # bits 1 - N-1
user_role: HashMap[address, Roles]
def only_admin():
# NOTE: The following performs `self.roles[msg.sender] & Roles.admin == Roles.admin`
assert self.roles[msg.sender] is Roles.admin # weird semantics...
# OR
assert Roles.admin in self.roles[msg.sender] # weird to read, but makes sense if you think about it Enums would make a good candidate for a VIP! |
So we are not going to support this? Feel free to close this issue. Right now I compensate the lacking of HashMap inside struct with two arrays: _roles: HashMap[bytes32, HashMap[address, bool]]
_admin_roles: HashMap[bytes32, bytes32] |
IMO it's a bad idea to support that behavior, without letting them be used in similar contexts between storage and memory. |
won't fix, it's a feature not a bug! |
Version Information
vyper --version
): 0.2.10+commit.418c85bpython --version
): Python 3.8.5pip freeze
):What's your issue about?
I would like to have HashMap inside struct. Right now I am translating OpenZeppelin code to Vyper. For example I'm translating this code: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/AccessControl.sol
They got mapping inside struct.
The text was updated successfully, but these errors were encountered: