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: self in pure functions #3027

Merged
merged 6 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/parser/features/decorators/test_pure.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ def foo() -> uint256:
)


def test_invalid_self_access(get_contract, assert_compile_failed):
assert_compile_failed(
lambda: get_contract(
"""
@pure
@external
def foo() -> address:
return self
"""
),
StateAccessViolation,
)


def test_invalid_call(get_contract, assert_compile_failed):
assert_compile_failed(
lambda: get_contract(
Expand Down
8 changes: 8 additions & 0 deletions vyper/semantics/validation/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ def __init__(
)
},
)

# Add references to `self` as standalone address
self_references = fn_node.get_descendants(vy_ast.Name, {"id": "self"})
standalone_self = [
n for n in self_references if not isinstance(n.get_ancestor(), vy_ast.Attribute)
]
node_list.extend(standalone_self) # type: ignore

for node in node_list:
t = node._metadata.get("type")
if isinstance(t, ContractFunction) and t.mutability == StateMutability.PURE:
Expand Down