Skip to content

Commit

Permalink
Use Atree non-readonly iterators in Transfer()
Browse files Browse the repository at this point in the history
If remove parameter is true in Transfer(), iterated values are
removed so non-readonly iterators need to be used.
  • Loading branch information
fxamacker committed Nov 21, 2023
1 parent 1ecf35c commit d35b7d6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -2738,7 +2738,9 @@ func (v *ArrayValue) Transfer(

if needsStoreTo || !isResourceKinded {

iterator, err := v.array.ReadOnlyIterator()
// Use non-readonly iterator here because iterated
// value can be removed if remove parameter is true.
iterator, err := v.array.Iterator()
if err != nil {
panic(errors.NewExternalError(err))
}
Expand Down Expand Up @@ -17302,7 +17304,12 @@ func (v *CompositeValue) Transfer(
}

if needsStoreTo || !isResourceKinded {
iterator, err := v.dictionary.ReadOnlyIterator()
// Use non-readonly iterator here because iterated
// value can be removed if remove parameter is true.
iterator, err := v.dictionary.Iterator(
StringAtreeValueComparator,
StringAtreeValueHashInput,
)
if err != nil {
panic(errors.NewExternalError(err))
}
Expand Down Expand Up @@ -18918,7 +18925,9 @@ func (v *DictionaryValue) Transfer(
valueComparator := newValueComparator(interpreter, locationRange)
hashInputProvider := newHashInputProvider(interpreter, locationRange)

iterator, err := v.dictionary.ReadOnlyIterator()
// Use non-readonly iterator here because iterated
// value can be removed if remove parameter is true.
iterator, err := v.dictionary.Iterator(valueComparator, hashInputProvider)
if err != nil {
panic(errors.NewExternalError(err))
}
Expand Down

0 comments on commit d35b7d6

Please sign in to comment.