You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vyper Version (output of vyper --version): 0.3.8+commit.046ea166
OS: OSX
Python Version (output of python --version): 3.8.0
What's your issue about?
Range expressions, when formed as range(x, x + CONSTANT), prevent x to be a call to state modifying functions. For example, the following contract would compile only if bar was a view or a pure function. Under its current form, the compiler raise a StateAccessViolation with the following reason: May not call state modifying function 'bar' within a range.
@internaldef bar()->uint256:
return0@externaldef test()-> (DynArray[uint256,6]):
b:DynArray[uint256,6] = []
for i in range(self.bar(),self.bar()+2):
b.append(i)
return b
However, it is possible to call the DynArray's pop function inside the range expression. If the dynamic array from which a value is popped is a state variable, the range expression is effectively calling a state modifying function. Note that only one value is popped.
For example, this contract compiles and a call to test output ([0,1],[1]), meaning that arr has been modified by the range by popping one value.
Version Information
vyper --version
): 0.3.8+commit.046ea166python --version
): 3.8.0What's your issue about?
Range expressions, when formed as
range(x, x + CONSTANT)
, preventx
to be a call to state modifying functions. For example, the following contract would compile only ifbar
was aview
or apure
function. Under its current form, the compiler raise aStateAccessViolation
with the following reason:May not call state modifying function 'bar' within a range
.However, it is possible to call the
DynArray
'spop
function inside the range expression. If the dynamic array from which a value is popped is a state variable, the range expression is effectively calling a state modifying function. Note that only one value is popped.For example, this contract compiles and a call to
test
output([0,1],[1])
, meaning thatarr
has been modified by the range by popping one value.The text was updated successfully, but these errors were encountered: