-
-
Notifications
You must be signed in to change notification settings - Fork 870
Open
Labels
needs triageneeds triageneeds triage
Description
Version Information
- vyper Version (output of
vyper --version): 34a9e08
What's your issue about?
@deploy
def __init__(a: uint256, b: DynArray[uint256, 10]):
a = 10yields:
vyper.exceptions.ImmutableViolation: Cannot write to calldata
contract "tests/custom/test.vy:6", function "__init__", line 6:4
5 def __init__(a: uint256, b: DynArray[uint256, 10]):
---> 6 a = 10
-----------^
but a doesn't come from calldata
this should be because the following line:
vyper/vyper/semantics/analysis/local.py
Line 317 in 8d5fa15
| location, modifiability = (DataLocation.CALLDATA, Modifiability.RUNTIME_CONSTANT) |
sets the location to CALLDATA even when the function is the constructor
i'm not sure whether the err msg is the only manifistation of the location assignment
How can it be fixed?
fixing just the error msg might involve smth like this
diff --git a/vyper/semantics/analysis/local.py b/vyper/semantics/analysis/local.py
index 70d8cbdd6..1bdca81f1 100644
--- a/vyper/semantics/analysis/local.py
+++ b/vyper/semantics/analysis/local.py
@@ -425,6 +425,13 @@ class FunctionAnalyzer(VyperNodeVisitorBase):
)
if info.location == DataLocation.CALLDATA:
+ if (
+ func_t.is_constructor
+ and info.var_info is not None
+ and isinstance(info.var_info.decl_node, vy_ast.arg)
+ ):
+ raise ImmutableViolation("Cannot assign to constructor argument")
+
raise ImmutableViolation("Cannot write to calldata")
if info.modifiability == Modifiability.RUNTIME_CONSTANT:Metadata
Metadata
Assignees
Labels
needs triageneeds triageneeds triage