-
-
Notifications
You must be signed in to change notification settings - Fork 836
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[lang]: pure access analysis #3895
fix[lang]: pure access analysis #3895
Conversation
fix access to module variables in pure functions. the `_validate_self_reference()` utility function was hard-coded to check the "self" name; remove it and replace with an analysis-based check. misc/refactor: - rename `VarInfo.is_module_variable()` to more fitting `VarInfo.is_state_variable()`.
recent best practices
- module storage variable - immutable variable - module immutable variable
@@ -38,7 +38,7 @@ | |||
from vyper.semantics.data_locations import DataLocation | |||
|
|||
# TODO consolidate some of these imports | |||
from vyper.semantics.environment import CONSTANT_ENVIRONMENT_VARS, MUTABLE_ENVIRONMENT_VARS | |||
from vyper.semantics.environment import CONSTANT_ENVIRONMENT_VARS |
Check notice
Code scanning / CodeQL
Cyclic import Note
vyper.semantics.environment
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #3895 +/- ##
==========================================
- Coverage 86.34% 86.07% -0.28%
==========================================
Files 92 92
Lines 14028 14036 +8
Branches 3083 3085 +2
==========================================
- Hits 12113 12081 -32
- Misses 1487 1517 +30
- Partials 428 438 +10 ☔ View full report in Codecov by Sentry. |
Is this a bug or an optimization? |
this isn't right? src = """
first: public(uint256)
second: public(uint256)
@internal
@pure
def foo() -> uint256:
return self.codesize
@deploy
def __init__():
self.first = self.foo()
@external
def bar():
self.second = self.foo()
"""
c = b.loads(src)
print(c.first())
c.bar()
print(c.second()) outputs:
|
hm yea we should probably ban codesize (it's not currently classified as a state variable) |
This PR introduced a regression. Tracking here: #3902. |
this commit fixes the ability to access module variables in pure functions. the `_validate_self_reference()` utility function was hard-coded to check the "self" name; remove it and replace with an analysis-based check. this commit also fixes the pure access check for immutable variables, and address members (e.g. `.codesize`) misc/refactor: * rename `VarInfo.is_module_variable()` to more fitting `VarInfo.is_state_variable()`. * refactor pure decorator tests to be in line with recent best practices
What I did
fix #3894, fix #3830
use analysis instead of pattern matching on syntax.
update code style for the pure decorator tests
How I did it
How to verify it
Commit message
Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)
Description for the changelog
Cute Animal Picture