patch 8.2.1051: crash when changing a list while using reduce() on it
Problem: Crash when changing a list while using reduce() on it.
Solution: Lock the list. (closes #6330)
diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim
index b1af87e..26b0e91 100644
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -709,6 +709,15 @@
call assert_fails("call reduce({}, { acc, val -> acc + val }, 1)", 'E897:')
call assert_fails("call reduce(0, { acc, val -> acc + val }, 1)", 'E897:')
call assert_fails("call reduce('', { acc, val -> acc + val }, 1)", 'E897:')
+
+ let g:lut = [1, 2, 3, 4]
+ func EvilRemove()
+ call remove(g:lut, 1)
+ return 1
+ endfunc
+ call assert_fails("call reduce(g:lut, { acc, val -> EvilRemove() }, 1)", 'E742:')
+ unlet g:lut
+ delfunc EvilRemove
endfunc
" splitting a string to a List using split()