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: constant folding on lhs of assignments #2137

Merged
merged 2 commits into from
Aug 31, 2020

Conversation

iamdefinitelyahuman
Copy link
Contributor

What I did

Fix a folding issue where constants used in binaries operations inside a subscript were not being correctly folded.

For example, the following currently fails to compile because FOO+1 is not folded:

FOO: constant(int128) = 3
bar: int128[100]

def foo():
    self.bar[FOO+1] = 1

How I did it

The existing logic does not fold constants on the left-hand side of an assignment, unless the constant's parent is a Subscript. To fix this, I'm now checking that the constant has an ancestor who is a Subscript.

How to verify it

Run tests. I expanded the test cases around this functionality to check this specific occurrence.

Cute Animal Picture

image

@codecov-commenter
Copy link

codecov-commenter commented Aug 30, 2020

Codecov Report

Merging #2137 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2137   +/-   ##
=======================================
  Coverage   84.90%   84.90%           
=======================================
  Files          83       83           
  Lines        8333     8333           
  Branches     2012     2012           
=======================================
  Hits         7075     7075           
  Misses        755      755           
  Partials      503      503           
Impacted Files Coverage Δ
vyper/ast/folding.py 91.48% <100.00%> (ø)

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 39e7664...6debcc8. Read the comment docs.

@fubuloubu fubuloubu merged commit 3eb9e7a into vyperlang:master Aug 31, 2020
@iamdefinitelyahuman iamdefinitelyahuman deleted the fix-folding branch October 9, 2020 17:36
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.

3 participants