diff options
| author | glepnir <glephunter@gmail.com> | 2025-07-23 08:40:24 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-22 17:40:24 -0700 |
| commit | 4fe51dfdae84f139bb92f8517aff914c4adb052c (patch) | |
| tree | f4243b093c37f42e579af4d88bbd93f6364e99e4 /test/functional/lua/iter_spec.lua | |
| parent | 1685c44dd463217db01643a97163420ed9f5b177 (diff) | |
| download | rneovim-4fe51dfdae84f139bb92f8517aff914c4adb052c.tar.gz rneovim-4fe51dfdae84f139bb92f8517aff914c4adb052c.tar.bz2 rneovim-4fe51dfdae84f139bb92f8517aff914c4adb052c.zip | |
fix(iter): ArrayIter:last returns nil when filtered to empty #34697
Problem: After filtering out all elements, ArrayIter:last still returns a stale element.
Solution: Add check for self._head == self._tail and return nil early.
Fix #34696
Diffstat (limited to 'test/functional/lua/iter_spec.lua')
| -rw-r--r-- | test/functional/lua/iter_spec.lua | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/test/functional/lua/iter_spec.lua b/test/functional/lua/iter_spec.lua index 64f8d5df79..1e4012521e 100644 --- a/test/functional/lua/iter_spec.lua +++ b/test/functional/lua/iter_spec.lua @@ -405,6 +405,15 @@ describe('vim.iter', function() local s = 'abcdefghijklmnopqrstuvwxyz' eq('z', vim.iter(vim.split(s, '')):last()) eq('z', vim.iter(vim.gsplit(s, '')):last()) + eq( + nil, + vim + .iter({ 1, 2, 3, 4, 5 }) + :filter(function() + return false + end) + :last() + ) end) it('enumerate()', function() |