patch 8.2.2321: Vim9: cannot nest closures
Problem: Vim9: cannot nest closures.
Solution: Add the nesting level to ISN_LOADOUTER and ISN_STOREOUTER.
(closes #7150, closes #7635)
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim
index f25b04a..ca9b90e 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -567,17 +567,17 @@
var res = execute('disass g:Append')
assert_match('<lambda>\d\_s*' ..
'local ..= arg\_s*' ..
- '\d LOADOUTER $0\_s*' ..
+ '\d LOADOUTER level 1 $0\_s*' ..
'\d LOAD arg\[-1\]\_s*' ..
'\d CONCAT\_s*' ..
- '\d STOREOUTER $0\_s*' ..
+ '\d STOREOUTER level 1 $0\_s*' ..
'\d RETURN 0',
res)
res = execute('disass g:Get')
assert_match('<lambda>\d\_s*' ..
'return local\_s*' ..
- '\d LOADOUTER $0\_s*' ..
+ '\d LOADOUTER level 1 $0\_s*' ..
'\d RETURN',
res)
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 3d4f4c9..efbf3d5 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -1812,6 +1812,16 @@
assert_match('def <lambda>\d\+(_: any, ...): number\n1 return 0\n enddef', body)
enddef
+def DoFilterThis(a: string): list<string>
+ # closure nested inside another closure using argument
+ var Filter = (l) => filter(l, (_, v) => stridx(v, a) == 0)
+ return ['x', 'y', 'a', 'x2', 'c']->Filter()
+enddef
+
+def Test_nested_closure_using_argument()
+ assert_equal(['x', 'x2'], DoFilterThis('x'))
+enddef
+
func Test_silent_echo()
CheckScreendump