Skip to content

Commit

Permalink
fix: disallow multiple assignments to immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
skellet0r committed Oct 4, 2021
1 parent 28665f6 commit 9ddf6df
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions vyper/semantics/types/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def __init__(
self.is_public = is_public
self.is_immutable = is_immutable

self._modification_count = 0

@property
def canonical_type(self) -> str:
"""
Expand Down Expand Up @@ -443,8 +445,15 @@ def validate_modification(self, node: Union[vy_ast.Assign, vy_ast.AugAssign]) ->
raise ImmutableViolation("Cannot write to calldata", node)
if self.is_constant:
raise ImmutableViolation("Immutable value cannot be written to", node)
if self.is_immutable and node.get_ancestor(vy_ast.FunctionDef).get("name") != "__init__":
raise ImmutableViolation("Immutable value cannot be written to", node)
if self.is_immutable:
if node.get_ancestor(vy_ast.FunctionDef).get("name") != "__init__":
raise ImmutableViolation("Immutable value cannot be written to", node)
if self._modification_count:
raise ImmutableViolation(
"Immutable value cannot be modified after assignment", node
)
self._modification_count += 1

if isinstance(node, vy_ast.AugAssign):
self.validate_numeric_op(node)

Expand Down

0 comments on commit 9ddf6df

Please sign in to comment.