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

allow lists of any type as loop variable #2616

Merged
merged 9 commits into from
Jan 23, 2022

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Jan 22, 2022

What I did

allow lists of any type as loop variable

How I did it

added a function new_type_to_old_type so that we can use the results of the type checker directly. eventually this can replace the old parse_type function.

How to verify it

struct X:
    y: uint256
@external
def foo(xs: DynArray[X, 5]) -> uint256:
    sum: uint256 = 0
    for x in xs:
        sum += x.y
    return sum

Description for the changelog

Cute Animal Picture

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

@charles-cooper charles-cooper changed the title Fix for typecheck allow lists of any type as loop variable Jan 22, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jan 22, 2022

Codecov Report

Merging #2616 (02e3c02) into master (df54e00) will decrease coverage by 0.12%.
The diff coverage is 65.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2616      +/-   ##
==========================================
- Coverage   86.66%   86.53%   -0.13%     
==========================================
  Files          91       92       +1     
  Lines        9433     9457      +24     
  Branches     2359     2369      +10     
==========================================
+ Hits         8175     8184       +9     
- Misses        773      781       +8     
- Partials      485      492       +7     
Impacted Files Coverage Δ
vyper/codegen/lll_node.py 94.02% <ø> (ø)
vyper/semantics/validation/local.py 91.48% <ø> (-0.76%) ⬇️
vyper/codegen/types/convert.py 61.29% <61.29%> (ø)
vyper/codegen/stmt.py 88.31% <100.00%> (+0.75%) ⬆️
vyper/builtin_functions/functions.py 88.26% <0.00%> (-0.34%) ⬇️

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 df54e00...02e3c02. Read the comment docs.

@charles-cooper charles-cooper marked this pull request as ready for review January 23, 2022 04:56
# override with type inferred at typechecking time
subtype = BaseType(self.stmt.target._metadata["type"]._id)
iter_list.typ.subtype = subtype
target_type = new_type_to_old_type(self.stmt.target._metadata["type"])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: investigate why target type != iter.subtype

@fubuloubu fubuloubu merged commit 5a7d8de into vyperlang:master Jan 23, 2022
tserg pushed a commit to tserg/vyper that referenced this pull request Feb 2, 2022
* allow arbitrary types in loop lists

* fix lint

* fix mypy

* add a test

* fix loop target inference

* prune some now-invalid tests

* fix lint

* add a note to revisit type checker

* add a nested static array test
tserg pushed a commit to tserg/vyper that referenced this pull request Feb 8, 2022
* allow arbitrary types in loop lists

* fix lint

* fix mypy

* add a test

* fix loop target inference

* prune some now-invalid tests

* fix lint

* add a note to revisit type checker

* add a nested static array test
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