Mercurial > vim
diff src/testdir/test_vim9_class.vim @ 31835:5ce5d78afcc9 v9.0.1250
patch 9.0.1250: cannot use an object method with :defer
Commit: https://github.com/vim/vim/commit/8dbab1d8ceb82a0fb693a1b7fcb57a2dfb4de068
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 27 20:14:02 2023 +0000
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 27 Jan 2023 21:15:03 +0100 |
parents | 3516e35f409f |
children | ffa11e2757e7 |
line wrap: on
line diff
--- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -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