Patch 9.0.1469
Problem: Deferred functions not called from autocommands.
Solution: Also go through the funccal_stack. (closes #12267)
Files: src/userfunc.c, src/testdir/test_user_func.vim
*** ../vim-9.0.1468/src/userfunc.c 2023-04-17 19:23:41.946037074 +0100
--- src/userfunc.c 2023-04-18 21:51:29.853426172 +0100
***************
*** 6122,6148 ****
ga_clear(&funccal->fc_defer);
}
/*
* Called when exiting: call all defer functions.
*/
void
invoke_all_defer(void)
{
! funccall_T *funccal;
! for (funccal = current_funccal; funccal != NULL;
! funccal = funccal->fc_caller)
! if (funccal->fc_ectx != NULL)
! {
! // :def function
! unwind_def_callstack(funccal->fc_ectx);
! may_invoke_defer_funcs(funccal->fc_ectx);
! }
! else
! {
! // legacy function
! handle_defer_one(funccal);
! }
}
/*
--- 6122,6155 ----
ga_clear(&funccal->fc_defer);
}
+ static void
+ invoke_funccall_defer(funccall_T *fc)
+ {
+ if (fc->fc_ectx != NULL)
+ {
+ // :def function
+ unwind_def_callstack(fc->fc_ectx);
+ may_invoke_defer_funcs(fc->fc_ectx);
+ }
+ else
+ {
+ // legacy function
+ handle_defer_one(fc);
+ }
+ }
+
/*
* Called when exiting: call all defer functions.
*/
void
invoke_all_defer(void)
{
! for (funccal_entry_T *fce = funccal_stack; fce != NULL; fce = fce->next)
! for (funccall_T *fc = fce->top_funccal; fc != NULL; fc = fc->fc_caller)
! invoke_funccall_defer(fc);
! for (funccall_T *fc = current_funccal; fc != NULL; fc = fc->fc_caller)
! invoke_funccall_defer(fc);
}
/*
*** ../vim-9.0.1468/src/testdir/test_user_func.vim 2023-04-18 21:04:49.431579535 +0100
--- src/testdir/test_user_func.vim 2023-04-18 21:45:49.631003518 +0100
***************
*** 702,707 ****
--- 702,734 ----
call delete('XQuitallDefThree')
endfunc
+ func Test_defer_quitall_autocmd()
+ let lines =<< trim END
+ autocmd User DeferAutocmdThree qa!
+
+ func DeferLevelTwo()
+ call writefile(['text'], 'XQuitallAutocmdTwo', 'D')
+ doautocmd User DeferAutocmdThree
+ endfunc
+
+ autocmd User DeferAutocmdTwo ++nested call DeferLevelTwo()
+
+ def DeferLevelOne()
+ call writefile(['text'], 'XQuitallAutocmdOne', 'D')
+ doautocmd User DeferAutocmdTwo
+ enddef
+
+ autocmd User DeferAutocmdOne ++nested call DeferLevelOne()
+
+ doautocmd User DeferAutocmdOne
+ END
+ call writefile(lines, 'XdeferQuitallAutocmd', 'D')
+ let res = system(GetVimCommand() .. ' -X -S XdeferQuitallAutocmd')
+ call assert_equal(0, v:shell_error)
+ call assert_false(filereadable('XQuitallAutocmdOne'))
+ call assert_false(filereadable('XQuitallAutocmdTwo'))
+ endfunc
+
func Test_defer_quitall_in_expr_func()
let lines =<< trim END
def DefIndex(idx: number, val: string): bool
*** ../vim-9.0.1468/src/version.c 2023-04-18 21:04:49.431579535 +0100
--- src/version.c 2023-04-18 21:47:18.721111421 +0100
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1469,
/**/
--
What do you get when you cross a joke with a rehtorical question?
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///