Mercurial > vim
diff src/testdir/test_vim9_func.vim @ 20295:bc2c9ea94ec1 v8.2.0703
patch 8.2.0703: Vim9: closure cannot store value in outer context
Commit: https://github.com/vim/vim/commit/b68b346e6db6d3f848e0a89905fcd7777b73c5d8
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed May 6 21:06:30 2020 +0200
patch 8.2.0703: Vim9: closure cannot store value in outer context
Problem: Vim9: closure cannot store value in outer context.
Solution: Make storing value in outer context work. Make :disassemble
accept a function reference.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 06 May 2020 21:15:04 +0200 |
parents | ce1b73835822 |
children | 98e7b880b7b1 |
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -738,6 +738,32 @@ def Test_closure_using_argument() unlet g:UseVararg enddef +def MakeGetAndAppendRefs() + let local = 'a' + + def Append(arg: string) + local ..= arg + enddef + g:Append = Append + + def Get(): string + return local + enddef + g:Get = Get +enddef + +def Test_closure_append_get() + MakeGetAndAppendRefs() + assert_equal('a', g:Get()) + g:Append('-b') + assert_equal('a-b', g:Get()) + g:Append('-c') + assert_equal('a-b-c', g:Get()) + + unlet g:Append + unlet g:Get +enddef + def Test_nested_closure() let local = 'text' def Closure(arg: string): string