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
The array and dictionary self modification functions aren't marked as view, and thus trigger an error when used in a view function, even if those arrays/dictionaries are on primitive/value types and local to the function (and thus not actually mutating storage).
Expected Behavior
Modifying arrays and dictionaries in other ways is allowed in a view context (eg. assignment), and so I would assume that calling methods on these types that modify those specific instances would also be okay.
Steps To Reproduce
access(all) view funhappyFunction() {
varmyArray = [0, 1, 2]
myArray[0] =1// modifying an element is okay
myArray.append(5) // adding a new element is an error
myArray.remove(at:0) // removing an element is an errorvarmyDict = {0: 0, 1: 1, 2: 2}
myDict[0] =1// modifying an element is okay
myDict[3] =3// adding a new element is okay
myDict.remove(key: 0) // removing an element is an error
}
Environment
- Cadence version: 1.0
- Network: n/a
The text was updated successfully, but these errors were encountered:
The new notion of view can probably extended further, but this is not a bug in the sense that it was promised to be supported.
@dete Is this blocking any work for the Crescendo release? If not, we can schedule it after that milestone. If it is, we'll need to investigate how this could be supported, which will likely be non-trivial in terms of effort required for including the whole feature (design, implementation, testing, documentation, release) and shift timelines accordingly
I would disagree about "not a bug", however. Having the built-in library be "const correct" is expected behaviour (at least expected by me, I guess!). Not a high priority, but I'm working on a PoC where I ran into this, and the work around using filter is not pretty!
yeah this is one of the most common errors ( second most common actually ) when upgrading mainnet contracts with cadence upgrader ( https://github.com/bluesign/cadenceUpgrader )
best work I came up with is: myArray = myArray.concat([5]) but I was hesitant to add it to converter.
Current Behavior
The array and dictionary self modification functions aren't marked as
view
, and thus trigger an error when used in aview
function, even if those arrays/dictionaries are on primitive/value types and local to the function (and thus not actually mutating storage).Expected Behavior
Modifying arrays and dictionaries in other ways is allowed in a view context (eg. assignment), and so I would assume that calling methods on these types that modify those specific instances would also be okay.
Steps To Reproduce
Environment
The text was updated successfully, but these errors were encountered: