Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
23248:a0e114c6b39e | 23249:43532077b5ff |
---|---|
1521 FuncA() | 1521 FuncA() |
1522 END | 1522 END |
1523 CheckScriptFailure(lines, 'E1012:') | 1523 CheckScriptFailure(lines, 'E1012:') |
1524 enddef | 1524 enddef |
1525 | 1525 |
1526 def Test_global_closure() | |
1527 var lines =<< trim END | |
1528 vim9script | |
1529 def ReverseEveryNLines(n: number, line1: number, line2: number) | |
1530 var mods = 'sil keepj keepp lockm ' | |
1531 var range = ':' .. line1 .. ',' .. line2 | |
1532 def g:Offset(): number | |
1533 var offset = (line('.') - line1 + 1) % n | |
1534 return offset != 0 ? offset : n | |
1535 enddef | |
1536 exe mods .. range .. 'g/^/exe "m .-" .. g:Offset()' | |
1537 enddef | |
1538 | |
1539 new | |
1540 repeat(['aaa', 'bbb', 'ccc'], 3)->setline(1) | |
1541 ReverseEveryNLines(3, 1, 9) | |
1542 END | |
1543 CheckScriptSuccess(lines) | |
1544 var expected = repeat(['ccc', 'bbb', 'aaa'], 3) | |
1545 assert_equal(expected, getline(1, 9)) | |
1546 bwipe! | |
1547 enddef | |
1548 | |
1526 def Test_failure_in_called_function() | 1549 def Test_failure_in_called_function() |
1527 # this was using the frame index as the return value | 1550 # this was using the frame index as the return value |
1528 var lines =<< trim END | 1551 var lines =<< trim END |
1529 vim9script | 1552 vim9script |
1530 au TerminalWinOpen * eval [][0] | 1553 au TerminalWinOpen * eval [][0] |