To: vim_dev@googlegroups.com Subject: Patch 9.0.0390 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0390 Problem: Cannot use a partial with :defer. Solution: Add the partial arguments before the other arguments. Disallow using a dictionary. Files: src/userfunc.c, src/errors.h, src/testdir/test_user_func.vim *** ../vim-9.0.0389/src/userfunc.c 2022-09-04 15:40:31.816188110 +0100 --- src/userfunc.c 2022-09-05 20:36:22.862782462 +0100 *************** *** 5567,5583 **** * Returns FAIL or OK. */ static int ! ex_defer_inner(char_u *name, char_u **arg, evalarg_T *evalarg) { typval_T argvars[MAX_FUNC_ARGS + 1]; // vars for arguments int argcount = 0; // number of arguments found if (current_funccal == NULL) { semsg(_(e_str_not_inside_function), "defer"); return FAIL; } ! if (get_func_arguments(arg, evalarg, FALSE, argvars, &argcount) == FAIL) { while (--argcount >= 0) clear_tv(&argvars[argcount]); --- 5567,5608 ---- * Returns FAIL or OK. */ static int ! ex_defer_inner( ! char_u *name, ! char_u **arg, ! partial_T *partial, ! evalarg_T *evalarg) { typval_T argvars[MAX_FUNC_ARGS + 1]; // vars for arguments + int partial_argc = 0; // number of partial arguments int argcount = 0; // number of arguments found + int r; if (current_funccal == NULL) { semsg(_(e_str_not_inside_function), "defer"); return FAIL; } ! if (partial != NULL) ! { ! if (partial->pt_dict != NULL) ! { ! emsg(_(e_cannot_use_partial_with_dictionary_for_defer)); ! return FAIL; ! } ! if (partial->pt_argc > 0) ! { ! int i; ! ! partial_argc = partial->pt_argc; ! for (i = 0; i < partial_argc; ++i) ! copy_tv(&partial->pt_argv[i], &argvars[i]); ! } ! } ! r = get_func_arguments(arg, evalarg, FALSE, ! argvars + partial_argc, &argcount); ! argcount += partial_argc; ! if (r == FAIL) { while (--argcount >= 0) clear_tv(&argvars[argcount]); *************** *** 5738,5744 **** if (eap->cmdidx == CMD_defer) { arg = startarg; ! failed = ex_defer_inner(name, &arg, &evalarg) == FAIL; } else { --- 5763,5769 ---- if (eap->cmdidx == CMD_defer) { arg = startarg; ! failed = ex_defer_inner(name, &arg, partial, &evalarg) == FAIL; } else { *** ../vim-9.0.0389/src/errors.h 2022-09-05 19:51:09.221360577 +0100 --- src/errors.h 2022-09-05 20:30:41.415198823 +0100 *************** *** 3326,3328 **** --- 3326,3332 ---- #endif EXTERN char e_window_unexpectedly_close_while_searching_for_tags[] INIT(= N_("E1299: Window unexpectedly closed while searching for tags")); + #ifdef FEAT_EVAL + EXTERN char e_cannot_use_partial_with_dictionary_for_defer[] + INIT(= N_("E1300: Cannot use a partial with dictionary for :defer")); + #endif *** ../vim-9.0.0389/src/testdir/test_user_func.vim 2022-09-03 21:35:50.188158217 +0100 --- src/testdir/test_user_func.vim 2022-09-05 21:15:12.184734904 +0100 *************** *** 529,536 **** bw! endfunc ! func AddDefer(arg) ! call extend(g:deferred, [a:arg]) endfunc func WithDeferTwo() --- 529,539 ---- bw! endfunc ! func AddDefer(arg1, ...) ! call extend(g:deferred, [a:arg1]) ! if a:0 == 1 ! call extend(g:deferred, [a:1]) ! endif endfunc func WithDeferTwo() *************** *** 550,555 **** --- 553,565 ---- call extend(g:deferred, ['end One']) endfunc + func WithPartialDefer() + call extend(g:deferred, ['in Partial']) + let Part = funcref('AddDefer', ['arg1']) + defer Part("arg2") + call extend(g:deferred, ['end Partial']) + endfunc + func Test_defer() let g:deferred = [] call WithDeferOne() *************** *** 558,563 **** --- 568,584 ---- unlet g:deferred call assert_equal('', glob('Xfuncdefer')) + + call assert_fails('defer delete("Xfuncdefer")->Another()', 'E488:') + call assert_fails('defer delete("Xfuncdefer").member', 'E488:') + + let g:deferred = [] + call WithPartialDefer() + call assert_equal(['in Partial', 'end Partial', 'arg1', 'arg2'], g:deferred) + unlet g:deferred + + let Part = funcref('AddDefer', ['arg1'], {}) + call assert_fails('defer Part("arg2")', 'E1300:') endfunc *** ../vim-9.0.0389/src/version.c 2022-09-05 19:51:09.221360577 +0100 --- src/version.c 2022-09-05 20:23:40.579761022 +0100 *************** *** 705,706 **** --- 705,708 ---- { /* Add new patch number below this line */ + /**/ + 390, /**/ -- hundred-and-one symptoms of being an internet addict: 9. All your daydreaming is preoccupied with getting a faster connection to the net: cable modem...100 Mbit...Fiber...1Gbit /// Bram Moolenaar -- Bram@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 ///