Mercurial > vim
diff src/testdir/test_vim9_func.vim @ 23249:43532077b5ff v8.2.2170
patch 8.2.2170: Vim9: a global function defined in a :def function fails
Commit: https://github.com/vim/vim/commit/f112f30a82f17114d8b08a0fb90928cd19440581
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 20 17:47:52 2020 +0100
patch 8.2.2170: Vim9: a global function defined in a :def function fails
Problem: Vim9: a global function defined in a :def function fails if it
uses the context.
Solution: Create a partial to store the closure context. (see #7410)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 20 Dec 2020 18:00:06 +0100 |
parents | cc24ac009f29 |
children | 35583da6397e |
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -1523,6 +1523,29 @@ def Test_nested_closure_fails() CheckScriptFailure(lines, 'E1012:') enddef +def Test_global_closure() + var lines =<< trim END + vim9script + def ReverseEveryNLines(n: number, line1: number, line2: number) + var mods = 'sil keepj keepp lockm ' + var range = ':' .. line1 .. ',' .. line2 + def g:Offset(): number + var offset = (line('.') - line1 + 1) % n + return offset != 0 ? offset : n + enddef + exe mods .. range .. 'g/^/exe "m .-" .. g:Offset()' + enddef + + new + repeat(['aaa', 'bbb', 'ccc'], 3)->setline(1) + ReverseEveryNLines(3, 1, 9) + END + CheckScriptSuccess(lines) + var expected = repeat(['ccc', 'bbb', 'aaa'], 3) + assert_equal(expected, getline(1, 9)) + bwipe! +enddef + def Test_failure_in_called_function() # this was using the frame index as the return value var lines =<< trim END