Skip to content

Fix: constant folding on lhs of assignments#2137

Merged
fubuloubu merged 2 commits into
vyperlang:masterfrom
iamdefinitelyahuman:fix-folding
Aug 31, 2020
Merged

Fix: constant folding on lhs of assignments#2137
fubuloubu merged 2 commits into
vyperlang:masterfrom
iamdefinitelyahuman:fix-folding

Conversation

@iamdefinitelyahuman

Copy link
Copy Markdown
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

codecov-commenter commented Aug 30, 2020

Copy link
Copy Markdown

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