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

len function doesn't work on static arrays #2347

Open
fubuloubu opened this issue Apr 11, 2021 · 6 comments
Open

len function doesn't work on static arrays #2347

fubuloubu opened this issue Apr 11, 2021 · 6 comments

Comments

@fubuloubu
Copy link
Member

It should be possible to ask for the length of a static array, and have it give you the same number back you used to set it up

def balanceOfBatch(accounts: address[50], ids: uint256[50]) -> uint256[100]:
    assert len(accounts) == len(ids), "ERC1155: accounts and ids length mismatch"

but tells me that len only function for bytes and string types

Originally posted by @QuetzalAzul in #2346

@iamdefinitelyahuman
Copy link
Contributor

This can be handled pretty easily during constant folding. Although given the length of an array is static, it seems redundant?

@fubuloubu
Copy link
Member Author

Although given the length of an array is static, it seems redundant?

It would be sort of redundant, but it would be a handy shortcut that's easier to read versus having to go check that the sizes match of two static arrays. It also introduces syntax that will become handy with dynamic arrays.

@charles-cooper
Copy link
Member

@fubuloubu What should len return, size in bytes, words or elements?

@fubuloubu
Copy link
Member Author

@fubuloubu What should len return, size in bytes, words or elements?

Number of elements of the list, basically SomeType[N] should just be N

@charles-cooper
Copy link
Member

@fubuloubu can we close this as dup of #1963?

@fubuloubu
Copy link
Member Author

I wouldn't say a dup of it, the two functions perform different roles, but yes they are related

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

No branches or pull requests

3 participants