0
0
mirror of https://github.com/vim/vim.git synced 2025-10-03 05:14:07 -04:00

patch 9.0.1250: cannot use an object method with :defer

Problem:    Cannot use an object method with :defer. (Ernie Rael)
Solution:   Find the object method and generate code to call it.
            (closes #11886)
This commit is contained in:
Bram Moolenaar
2023-01-27 20:14:02 +00:00
parent 657aea7fc4
commit 8dbab1d8ce
8 changed files with 99 additions and 21 deletions

View File

@@ -1331,5 +1331,35 @@ def Test_closure_in_class()
v9.CheckScriptSuccess(lines)
enddef
def Test_defer_with_object()
var lines =<< trim END
vim9script
class CWithEE
def Enter()
g:result ..= "entered/"
enddef
def Exit()
g:result ..= "exited"
enddef
endclass
def With(ee: CWithEE, F: func)
ee.Enter()
defer ee.Exit()
F()
enddef
g:result = ''
var obj = CWithEE.new()
obj->With(() => {
g:result ..= "called/"
})
assert_equal('entered/called/exited', g:result)
END
v9.CheckScriptSuccess(lines)
unlet g:result
enddef
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker