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

fix: static list of structs as arg #2515

Merged
merged 3 commits into from
Oct 26, 2021

Conversation

skellet0r
Copy link
Contributor

What I did

Enable a list of structs as an argument.

Contrived Example:

struct Foo:
    x: uint256
    y: uint256
    z: bytes32
    a: String[32]

@external
def bar(_input: Foo[10]):
    sum: uint256 = 0
    hash: bytes32 = EMPTY_BYTES32
    for i in range(10):
        sum += _input[i].x * _input[i].y
        hash = keccak256(concat(hash, _input[i].z))

How I did it

I changed like one line of code which prevented this from working.

How to verify it

Compile the above example, check the simple test (more test case ideas are welcome)

Description for the changelog

  • fix: allow list of structs as an argument

Cute Animal Picture

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

@codecov-commenter
Copy link

codecov-commenter commented Oct 26, 2021

Codecov Report

Merging #2515 (a348ff5) into master (317625f) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2515      +/-   ##
==========================================
- Coverage   84.64%   84.62%   -0.03%     
==========================================
  Files          94       94              
  Lines        9325     9325              
  Branches     2103     2103              
==========================================
- Hits         7893     7891       -2     
- Misses        944      946       +2     
  Partials      488      488              
Impacted Files Coverage Δ
vyper/old_codegen/types/types.py 82.96% <100.00%> (ø)
vyper/builtin_functions/functions.py 88.68% <0.00%> (-0.34%) ⬇️
..._codegen/function_definitions/external_function.py 97.95% <0.00%> (+1.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 317625f...a348ff5. Read the comment docs.

@charles-cooper
Copy link
Member

Almost too easy!

@charles-cooper
Copy link
Member

Possible to add a test for structs with dynamic data e.g. bytes?

@skellet0r
Copy link
Contributor Author

skellet0r commented Oct 26, 2021

XD

Possible to add a test for structs with dynamic data e.g. bytes?

oh definitely ! Just popped in my head, 2-D lists of structs is possible now too Foo[10][10]

@charles-cooper
Copy link
Member

thanks!

@charles-cooper charles-cooper merged commit 03642a0 into vyperlang:master Oct 26, 2021
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

3 participants