diff --git a/runtime/interpreter/value.go b/runtime/interpreter/value.go index b0858ce317..782673d4a3 100644 --- a/runtime/interpreter/value.go +++ b/runtime/interpreter/value.go @@ -2989,10 +2989,8 @@ func (v *ArrayValue) Filter( return invocation } - iterator, err := v.array.Iterator() - i := 0 - err = v.array.Iterate( + err := v.array.Iterate( func(item atree.Value) (bool, error) { arrayElement := MustConvertStoredValue(interpreter, item) @@ -3013,6 +3011,11 @@ func (v *ArrayValue) Filter( panic(errors.NewExternalError(err)) } + iterator, err := v.array.Iterator() + if err != nil { + panic(errors.NewExternalError(err)) + } + return NewArrayValueWithIterator( interpreter, NewVariableSizedStaticType(interpreter, v.Type.ElementType()),