1
0
forked from aniani/vim

patch 8.2.3788: lambda for option that is a function may be freed

Problem:    Lambda for option that is a function may be garbage collected.
Solution:   Set a reference in the funcref. (Yegappan Lakshmanan,
            closes #9330)
This commit is contained in:
Yegappan Lakshmanan
2021-12-12 16:26:44 +00:00
committed by Bram Moolenaar
parent 6e371ecb27
commit 6ae8fae869
19 changed files with 1090 additions and 897 deletions

View File

@@ -4516,6 +4516,18 @@ garbage_collect(int testing)
// callbacks in buffers // callbacks in buffers
abort = abort || set_ref_in_buffers(copyID); abort = abort || set_ref_in_buffers(copyID);
// 'completefunc', 'omnifunc' and 'thesaurusfunc' callbacks
abort = abort || set_ref_in_insexpand_funcs(copyID);
// 'operatorfunc' callback
abort = abort || set_ref_in_opfunc(copyID);
// 'tagfunc' callback
abort = abort || set_ref_in_tagfunc(copyID);
// 'imactivatefunc' and 'imstatusfunc' callbacks
abort = abort || set_ref_in_im_funcs(copyID);
#ifdef FEAT_LUA #ifdef FEAT_LUA
abort = abort || set_ref_in_lua(copyID); abort = abort || set_ref_in_lua(copyID);
#endif #endif
@@ -4743,6 +4755,22 @@ set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack)
return abort; return abort;
} }
/*
* Mark the partial in callback 'cb' with "copyID".
*/
int
set_ref_in_callback(callback_T *cb, int copyID)
{
typval_T tv;
if (cb->cb_name == NULL || *cb->cb_name == NUL || cb->cb_partial == NULL)
return FALSE;
tv.v_type = VAR_PARTIAL;
tv.vval.v_partial = cb->cb_partial;
return set_ref_in_item(&tv, copyID, NULL, NULL);
}
/* /*
* Mark all lists and dicts referenced through typval "tv" with "copyID". * Mark all lists and dicts referenced through typval "tv" with "copyID".
* "list_stack" is used to add lists to be marked. Can be NULL. * "list_stack" is used to add lists to be marked. Can be NULL.

View File

@@ -26,31 +26,25 @@ set_ref_in_buffers(int copyID)
FOR_ALL_BUFFERS(bp) FOR_ALL_BUFFERS(bp)
{ {
listener_T *lnr; listener_T *lnr;
typval_T tv;
for (lnr = bp->b_listener; !abort && lnr != NULL; lnr = lnr->lr_next) for (lnr = bp->b_listener; !abort && lnr != NULL; lnr = lnr->lr_next)
{ abort = abort || set_ref_in_callback(&lnr->lr_callback, copyID);
if (lnr->lr_callback.cb_partial != NULL)
{
tv.v_type = VAR_PARTIAL;
tv.vval.v_partial = lnr->lr_callback.cb_partial;
abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
}
}
# ifdef FEAT_JOB_CHANNEL # ifdef FEAT_JOB_CHANNEL
if (!abort && bp->b_prompt_callback.cb_partial != NULL) if (!abort)
{ abort = abort || set_ref_in_callback(&bp->b_prompt_callback, copyID);
tv.v_type = VAR_PARTIAL; if (!abort)
tv.vval.v_partial = bp->b_prompt_callback.cb_partial; abort = abort || set_ref_in_callback(&bp->b_prompt_interrupt, copyID);
abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
}
if (!abort && bp->b_prompt_interrupt.cb_partial != NULL)
{
tv.v_type = VAR_PARTIAL;
tv.vval.v_partial = bp->b_prompt_interrupt.cb_partial;
abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
}
# endif # endif
#ifdef FEAT_COMPL_FUNC
if (!abort)
abort = abort || set_ref_in_callback(&bp->b_cfu_cb, copyID);
if (!abort)
abort = abort || set_ref_in_callback(&bp->b_ofu_cb, copyID);
if (!abort)
abort = abort || set_ref_in_callback(&bp->b_tsrfu_cb, copyID);
#endif
if (!abort)
abort = abort || set_ref_in_callback(&bp->b_tfu_cb, copyID);
if (abort) if (abort)
break; break;
} }

View File

@@ -1395,7 +1395,6 @@ ex_let_option(
char_u *tofree = NULL; char_u *tofree = NULL;
char_u numbuf[NUMBUFLEN]; char_u numbuf[NUMBUFLEN];
c1 = *p; c1 = *p;
*p = NUL; *p = NUL;

View File

@@ -117,7 +117,7 @@ call_imstatusfunc(void)
void void
free_xim_stuff(void) free_xim_stuff(void)
{ {
#if defined(FEAT_EVAL) && \ # if defined(FEAT_EVAL) && \
(defined(FEAT_XIM) || defined(IME_WITHOUT_XIM) || defined(VIMDLL)) (defined(FEAT_XIM) || defined(IME_WITHOUT_XIM) || defined(VIMDLL))
free_callback(&imaf_cb); free_callback(&imaf_cb);
free_callback(&imsf_cb); free_callback(&imsf_cb);
@@ -125,6 +125,24 @@ free_xim_stuff(void)
} }
#endif #endif
/*
* Mark the global 'imactivatefunc' and 'imstatusfunc' callbacks with 'copyID'
* so that they are not garbage collected.
*/
int
set_ref_in_im_funcs(int copyID UNUSED)
{
int abort = FALSE;
#if defined(FEAT_EVAL) && \
(defined(FEAT_XIM) || defined(IME_WITHOUT_XIM) || defined(VIMDLL))
abort = set_ref_in_callback(&imaf_cb, copyID);
abort = abort || set_ref_in_callback(&imsf_cb, copyID);
#endif
return abort;
}
#if defined(FEAT_XIM) || defined(PROTO) #if defined(FEAT_XIM) || defined(PROTO)

View File

@@ -2341,6 +2341,21 @@ set_thesaurusfunc_option(void)
return retval; return retval;
} }
/*
* Mark the global 'completefunc' 'omnifunc' and 'thesaurusfunc' callbacks with
* 'copyID' so that they are not garbage collected.
*/
int
set_ref_in_insexpand_funcs(int copyID)
{
int abort = FALSE;
abort = set_ref_in_callback(&cfu_cb, copyID);
abort = abort || set_ref_in_callback(&ofu_cb, copyID);
abort = abort || set_ref_in_callback(&tsrfu_cb, copyID);
return abort;
}
/* /*
* Get the user-defined completion function name for completion 'type' * Get the user-defined completion function name for completion 'type'

View File

@@ -3341,12 +3341,28 @@ set_operatorfunc_option(void)
void void
free_operatorfunc_option(void) free_operatorfunc_option(void)
{ {
# ifdef FEAT_EVAL # ifdef FEAT_EVAL
free_callback(&opfunc_cb); free_callback(&opfunc_cb);
# endif # endif
} }
#endif #endif
/*
* Mark the global 'operatorfunc' callback with 'copyID' so that it is not
* garbage collected.
*/
int
set_ref_in_opfunc(int copyID UNUSED)
{
int abort = FALSE;
#ifdef FEAT_EVAL
abort = set_ref_in_callback(&opfunc_cb, copyID);
#endif
return abort;
}
/* /*
* Handle the "g@" operator: call 'operatorfunc'. * Handle the "g@" operator: call 'operatorfunc'.
*/ */

View File

@@ -52,6 +52,7 @@ int set_ref_in_ht(hashtab_T *ht, int copyID, list_stack_T **list_stack);
int set_ref_in_dict(dict_T *d, int copyID); int set_ref_in_dict(dict_T *d, int copyID);
int set_ref_in_list(list_T *ll, int copyID); int set_ref_in_list(list_T *ll, int copyID);
int set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack); int set_ref_in_list_items(list_T *l, int copyID, ht_stack_T **ht_stack);
int set_ref_in_callback(callback_T *cb, int copyID);
int set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack_T **list_stack); int set_ref_in_item(typval_T *tv, int copyID, ht_stack_T **ht_stack, list_stack_T **list_stack);
char_u *echo_string_core(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID, int echo_style, int restore_copyID, int composite_val); char_u *echo_string_core(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID, int echo_style, int restore_copyID, int composite_val);
char_u *echo_string(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID); char_u *echo_string(typval_T *tv, char_u **tofree, char_u *numbuf, int copyID);

View File

@@ -2,6 +2,7 @@
int set_imactivatefunc_option(void); int set_imactivatefunc_option(void);
int set_imstatusfunc_option(void); int set_imstatusfunc_option(void);
void free_xim_stuff(void); void free_xim_stuff(void);
int set_ref_in_im_funcs(int copyID);
void im_set_active(int active); void im_set_active(int active);
void xim_set_focus(int focus); void xim_set_focus(int focus);
void im_set_position(int row, int col); void im_set_position(int row, int col);

View File

@@ -44,6 +44,7 @@ void set_buflocal_cfu_callback(buf_T *buf);
int set_omnifunc_option(void); int set_omnifunc_option(void);
void set_buflocal_ofu_callback(buf_T *buf); void set_buflocal_ofu_callback(buf_T *buf);
int set_thesaurusfunc_option(void); int set_thesaurusfunc_option(void);
int set_ref_in_insexpand_funcs(int copyID);
callback_T *get_insert_callback(int type); callback_T *get_insert_callback(int type);
void f_complete(typval_T *argvars, typval_T *rettv); void f_complete(typval_T *argvars, typval_T *rettv);
void f_complete_add(typval_T *argvars, typval_T *rettv); void f_complete_add(typval_T *argvars, typval_T *rettv);

View File

@@ -19,5 +19,6 @@ void clear_oparg(oparg_T *oap);
void cursor_pos_info(dict_T *dict); void cursor_pos_info(dict_T *dict);
int set_operatorfunc_option(void); int set_operatorfunc_option(void);
void free_operatorfunc_option(void); void free_operatorfunc_option(void);
int set_ref_in_opfunc(int copyID);
void do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank); void do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank);
/* vim: set ft=c : */ /* vim: set ft=c : */

View File

@@ -1,6 +1,7 @@
/* tag.c */ /* tag.c */
int set_tagfunc_option(void); int set_tagfunc_option(void);
void free_tagfunc_option(void); void free_tagfunc_option(void);
int set_ref_in_tagfunc(int copyID);
void set_buflocal_tfu_callback(buf_T *buf); void set_buflocal_tfu_callback(buf_T *buf);
int do_tag(char_u *tag, int type, int count, int forceit, int verbose); int do_tag(char_u *tag, int type, int count, int forceit, int verbose);
void tag_freematch(void); void tag_freematch(void);

View File

@@ -7675,7 +7675,8 @@ set_errorlist(
} }
/* /*
* Mark the context as in use for all the lists in a quickfix stack. * Mark the quickfix context and callback function as in use for all the lists
* in a quickfix stack.
*/ */
static int static int
mark_quickfix_ctx(qf_info_T *qi, int copyID) mark_quickfix_ctx(qf_info_T *qi, int copyID)
@@ -7683,13 +7684,17 @@ mark_quickfix_ctx(qf_info_T *qi, int copyID)
int i; int i;
int abort = FALSE; int abort = FALSE;
typval_T *ctx; typval_T *ctx;
callback_T *cb;
for (i = 0; i < LISTCOUNT && !abort; ++i) for (i = 0; i < LISTCOUNT && !abort; ++i)
{ {
ctx = qi->qf_lists[i].qf_ctx; ctx = qi->qf_lists[i].qf_ctx;
if (ctx != NULL && ctx->v_type != VAR_NUMBER if (ctx != NULL && ctx->v_type != VAR_NUMBER
&& ctx->v_type != VAR_STRING && ctx->v_type != VAR_FLOAT) && ctx->v_type != VAR_STRING && ctx->v_type != VAR_FLOAT)
abort = set_ref_in_item(ctx, copyID, NULL, NULL); abort = abort || set_ref_in_item(ctx, copyID, NULL, NULL);
cb = &qi->qf_lists[i].qftf_cb;
abort = abort || set_ref_in_callback(cb, copyID);
} }
return abort; return abort;
@@ -7710,6 +7715,10 @@ set_ref_in_quickfix(int copyID)
if (abort) if (abort)
return abort; return abort;
abort = set_ref_in_callback(&qftf_cb, copyID);
if (abort)
return abort;
FOR_ALL_TAB_WINDOWS(tp, win) FOR_ALL_TAB_WINDOWS(tp, win)
{ {
if (win->w_llist != NULL) if (win->w_llist != NULL)

View File

@@ -133,15 +133,31 @@ set_tagfunc_option(void)
return OK; return OK;
} }
# if defined(EXITFREE) || defined(PROTO) #if defined(EXITFREE) || defined(PROTO)
void void
free_tagfunc_option(void) free_tagfunc_option(void)
{ {
# ifdef FEAT_EVAL # ifdef FEAT_EVAL
free_callback(&tfu_cb); free_callback(&tfu_cb);
# endif
}
# endif # endif
}
#endif
/*
* Mark the global 'tagfunc' callback with 'copyID' so that it is not garbage
* collected.
*/
int
set_ref_in_tagfunc(int copyID UNUSED)
{
int abort = FALSE;
#ifdef FEAT_EVAL
abort = set_ref_in_callback(&tfu_cb, copyID);
#endif
return abort;
}
/* /*
* Copy the global 'tagfunc' callback function to the buffer-local 'tagfunc' * Copy the global 'tagfunc' callback function to the buffer-local 'tagfunc'

View File

@@ -119,83 +119,142 @@ func Test_imactivatefunc_imstatusfunc_callback()
let g:IMstatusfunc_called += 1 let g:IMstatusfunc_called += 1
return 1 return 1
endfunc endfunc
let g:IMactivatefunc_called = 0
let g:IMstatusfunc_called = 0
set iminsert=2 set iminsert=2
" Test for using a function() let lines =<< trim END
set imactivatefunc=function('IMactivatefunc1') LET g:IMactivatefunc_called = 0
set imstatusfunc=function('IMstatusfunc1') LET g:IMstatusfunc_called = 0
normal! i
" Using a funcref variable to set 'completefunc' #" Test for using a function()
let Fn1 = function('IMactivatefunc1') set imactivatefunc=function('g:IMactivatefunc1')
let &imactivatefunc = Fn1 set imstatusfunc=function('g:IMstatusfunc1')
let Fn2 = function('IMstatusfunc1') normal! i
let &imstatusfunc = Fn2
normal! i
" Using a string(funcref variable) to set 'completefunc' #" Using a funcref variable to set 'completefunc'
let &imactivatefunc = string(Fn1) VAR Fn1 = function('g:IMactivatefunc1')
let &imstatusfunc = string(Fn2) LET &imactivatefunc = Fn1
normal! i VAR Fn2 = function('g:IMstatusfunc1')
LET &imstatusfunc = Fn2
normal! i
" Test for using a funcref() #" Using a string(funcref variable) to set 'completefunc'
set imactivatefunc=funcref('IMactivatefunc1') LET &imactivatefunc = string(Fn1)
set imstatusfunc=funcref('IMstatusfunc1') LET &imstatusfunc = string(Fn2)
normal! i normal! i
" Using a funcref variable to set 'imactivatefunc' #" Test for using a funcref()
let Fn1 = funcref('IMactivatefunc1') set imactivatefunc=funcref('g:IMactivatefunc1')
let &imactivatefunc = Fn1 set imstatusfunc=funcref('g:IMstatusfunc1')
let Fn2 = funcref('IMstatusfunc1') normal! i
let &imstatusfunc = Fn2
normal! i
" Using a string(funcref variable) to set 'imactivatefunc' #" Using a funcref variable to set 'imactivatefunc'
let &imactivatefunc = string(Fn1) LET Fn1 = funcref('g:IMactivatefunc1')
let &imstatusfunc = string(Fn2) LET &imactivatefunc = Fn1
normal! i LET Fn2 = funcref('g:IMstatusfunc1')
LET &imstatusfunc = Fn2
normal! i
" Test for using a lambda function #" Using a string(funcref variable) to set 'imactivatefunc'
set imactivatefunc={a\ ->\ IMactivatefunc1(a)} LET &imactivatefunc = string(Fn1)
set imstatusfunc={\ ->\ IMstatusfunc1()} LET &imstatusfunc = string(Fn2)
normal! i normal! i
" Set 'imactivatefunc' and 'imstatusfunc' to a lambda expression #" Test for using a lambda function
let &imactivatefunc = {a -> IMactivatefunc1(a)} VAR optval = "LSTART a LMIDDLE IMactivatefunc1(a) LEND"
let &imstatusfunc = { -> IMstatusfunc1()} LET optval = substitute(optval, ' ', '\\ ', 'g')
normal! i exe "set imactivatefunc=" .. optval
LET optval = "LSTART LMIDDLE IMstatusfunc1() LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set imstatusfunc=" .. optval
normal! i
" Set 'imactivatefunc' and 'imstatusfunc' to a string(lambda expression) #" Set 'imactivatefunc' and 'imstatusfunc' to a lambda expression
let &imactivatefunc = '{a -> IMactivatefunc1(a)}' LET &imactivatefunc = LSTART a LMIDDLE IMactivatefunc1(a) LEND
let &imstatusfunc = '{ -> IMstatusfunc1()}' LET &imstatusfunc = LSTART LMIDDLE IMstatusfunc1() LEND
normal! i normal! i
" Set 'imactivatefunc' 'imstatusfunc' to a variable with a lambda expression #" Set 'imactivatefunc' and 'imstatusfunc' to a string(lambda expression)
let Lambda1 = {a -> IMactivatefunc1(a)} LET &imactivatefunc = 'LSTART a LMIDDLE IMactivatefunc1(a) LEND'
let Lambda2 = { -> IMstatusfunc1()} LET &imstatusfunc = 'LSTART LMIDDLE IMstatusfunc1() LEND'
let &imactivatefunc = Lambda1 normal! i
let &imstatusfunc = Lambda2
normal! i
" Set 'imactivatefunc' 'imstatusfunc' to a string(variable with a lambda #" Set 'imactivatefunc' 'imstatusfunc' to a variable with a lambda
" expression) #" expression
let &imactivatefunc = string(Lambda1) VAR Lambda1 = LSTART a LMIDDLE IMactivatefunc1(a) LEND
let &imstatusfunc = string(Lambda2) VAR Lambda2 = LSTART LMIDDLE IMstatusfunc1() LEND
normal! i LET &imactivatefunc = Lambda1
LET &imstatusfunc = Lambda2
normal! i
" Test for clearing the 'completefunc' option #" Set 'imactivatefunc' 'imstatusfunc' to a string(variable with a lambda
set imactivatefunc='' imstatusfunc='' #" expression)
set imactivatefunc& imstatusfunc& LET &imactivatefunc = string(Lambda1)
LET &imstatusfunc = string(Lambda2)
normal! i
call assert_fails("set imactivatefunc=function('abc')", "E700:") #" Test for clearing the 'completefunc' option
call assert_fails("set imstatusfunc=function('abc')", "E700:") set imactivatefunc='' imstatusfunc=''
call assert_fails("set imactivatefunc=funcref('abc')", "E700:") set imactivatefunc& imstatusfunc&
call assert_fails("set imstatusfunc=funcref('abc')", "E700:")
call assert_equal(11, g:IMactivatefunc_called) set imactivatefunc=g:IMactivatefunc1
call assert_equal(22, g:IMstatusfunc_called) set imstatusfunc=g:IMstatusfunc1
call assert_fails("set imactivatefunc=function('abc')", "E700:")
call assert_fails("set imstatusfunc=function('abc')", "E700:")
call assert_fails("set imactivatefunc=funcref('abc')", "E700:")
call assert_fails("set imstatusfunc=funcref('abc')", "E700:")
call assert_fails("LET &imstatusfunc = function('abc')", "E700:")
call assert_fails("LET &imactivatefunc = function('abc')", "E700:")
normal! i
#" set 'imactivatefunc' and 'imstatusfunc' to a non-existing function
set imactivatefunc=IMactivatefunc1
set imstatusfunc=IMstatusfunc1
call assert_fails("set imactivatefunc=function('NonExistingFunc')", 'E700:')
call assert_fails("set imstatusfunc=function('NonExistingFunc')", 'E700:')
call assert_fails("LET &imactivatefunc = function('NonExistingFunc')", 'E700:')
call assert_fails("LET &imstatusfunc = function('NonExistingFunc')", 'E700:')
normal! i
call assert_equal(13, g:IMactivatefunc_called)
call assert_equal(26, g:IMstatusfunc_called)
END
call CheckLegacyAndVim9Success(lines)
" Using Vim9 lambda expression in legacy context should fail
set imactivatefunc=(a)\ =>\ IMactivatefunc1(a)
set imstatusfunc=IMstatusfunc1
call assert_fails('normal! i', 'E117:')
set imactivatefunc=IMactivatefunc1
set imstatusfunc=()\ =>\ IMstatusfunc1(a)
call assert_fails('normal! i', 'E117:')
" set 'imactivatefunc' and 'imstatusfunc' to a partial with dict. This used
" to cause a crash.
func SetIMFunc()
let params1 = {'activate': function('g:DictActivateFunc')}
let params2 = {'status': function('g:DictStatusFunc')}
let &imactivatefunc = params1.activate
let &imstatusfunc = params2.status
endfunc
func g:DictActivateFunc(_) dict
endfunc
func g:DictStatusFunc(_) dict
endfunc
call SetIMFunc()
new
call SetIMFunc()
bw
call test_garbagecollect_now()
new
set imactivatefunc=
set imstatusfunc=
wincmd w
set imactivatefunc=
set imstatusfunc=
:%bw!
delfunc g:DictActivateFunc
delfunc g:DictStatusFunc
delfunc SetIMFunc
" Vim9 tests " Vim9 tests
let lines =<< trim END let lines =<< trim END
@@ -217,59 +276,12 @@ func Test_imactivatefunc_imstatusfunc_callback()
set imstatusfunc=function('IMstatusfunc1') set imstatusfunc=function('IMstatusfunc1')
normal! i normal! i
# Test for using a lambda
&imactivatefunc = '(a) => IMactivatefunc1(a)'
&imstatusfunc = '() => IMstatusfunc1()'
normal! i
# Test for using a variable with a lambda expression
var Fn1: func = (active) => {
g:IMactivatefunc_called += 1
return 1
}
var Fn2: func = () => {
g:IMstatusfunc_called += 1
return 1
}
&imactivatefunc = Fn1
&imstatusfunc = Fn2
normal! i
# Test for using a string(variable with a lambda expression)
&imactivatefunc = string(Fn1)
&imstatusfunc = string(Fn2)
normal! i
assert_equal(4, g:IMactivatefunc_called)
assert_equal(8, g:IMstatusfunc_called)
set iminsert=0 set iminsert=0
set imactivatefunc= set imactivatefunc=
set imstatusfunc= set imstatusfunc=
END END
call CheckScriptSuccess(lines) call CheckScriptSuccess(lines)
" Using Vim9 lambda expression in legacy context should fail
set imactivatefunc=(a)\ =>\ IMactivatefunc1(a)
set imstatusfunc=IMstatusfunc1
call assert_fails('normal! i', 'E117:')
set imactivatefunc=IMactivatefunc1
set imstatusfunc=()\ =>\ IMstatusfunc1(a)
call assert_fails('normal! i', 'E117:')
" set 'imactivatefunc' and 'imstatusfunc' to a non-existing function
set imactivatefunc=IMactivatefunc1
set imstatusfunc=IMstatusfunc1
call assert_fails("set imactivatefunc=function('NonExistingFunc')", 'E700:')
call assert_fails("set imstatusfunc=function('NonExistingFunc')", 'E700:')
call assert_fails("let &imactivatefunc = function('NonExistingFunc')", 'E700:')
call assert_fails("let &imstatusfunc = function('NonExistingFunc')", 'E700:')
let g:IMactivatefunc_called = 0
let g:IMstatusfunc_called = 0
normal! i
call assert_equal(2, g:IMactivatefunc_called)
call assert_equal(2, g:IMstatusfunc_called)
" cleanup " cleanup
delfunc IMactivatefunc1 delfunc IMactivatefunc1
delfunc IMstatusfunc1 delfunc IMstatusfunc1

File diff suppressed because it is too large Load Diff

View File

@@ -448,110 +448,122 @@ func Test_opfunc_callback()
let g:OpFuncArgs = [a:val, a:type] let g:OpFuncArgs = [a:val, a:type]
endfunc endfunc
" Test for using a function() let lines =<< trim END
set opfunc=function('MyopFunc',\ [11]) #" Test for using a function()
let g:OpFuncArgs = [] set opfunc=function('g:MyopFunc',\ [10])
normal! g@l LET g:OpFuncArgs = []
call assert_equal([11, 'char'], g:OpFuncArgs) normal! g@l
call assert_equal([10, 'char'], g:OpFuncArgs)
" Using a funcref variable to set 'operatorfunc' #" Using a funcref variable to set 'operatorfunc'
let Fn = function('MyopFunc', [12]) VAR Fn = function('g:MyopFunc', [11])
let &opfunc = Fn LET &opfunc = Fn
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
normal! g@l normal! g@l
call assert_equal([12, 'char'], g:OpFuncArgs) call assert_equal([11, 'char'], g:OpFuncArgs)
" Using a string(funcref_variable) to set 'operatorfunc' #" Using a string(funcref_variable) to set 'operatorfunc'
let Fn = function('MyopFunc', [13]) LET Fn = function('g:MyopFunc', [12])
let &operatorfunc = string(Fn) LET &operatorfunc = string(Fn)
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
normal! g@l normal! g@l
call assert_equal([13, 'char'], g:OpFuncArgs) call assert_equal([12, 'char'], g:OpFuncArgs)
" Test for using a funcref() #" Test for using a funcref()
set operatorfunc=funcref('MyopFunc',\ [14]) set operatorfunc=funcref('g:MyopFunc',\ [13])
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
normal! g@l normal! g@l
call assert_equal([14, 'char'], g:OpFuncArgs) call assert_equal([13, 'char'], g:OpFuncArgs)
" Using a funcref variable to set 'operatorfunc' #" Using a funcref variable to set 'operatorfunc'
let Fn = funcref('MyopFunc', [15]) LET Fn = funcref('g:MyopFunc', [14])
let &opfunc = Fn LET &opfunc = Fn
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
normal! g@l normal! g@l
call assert_equal([15, 'char'], g:OpFuncArgs) call assert_equal([14, 'char'], g:OpFuncArgs)
" Using a string(funcref_variable) to set 'operatorfunc' #" Using a string(funcref_variable) to set 'operatorfunc'
let Fn = funcref('MyopFunc', [16]) LET Fn = funcref('g:MyopFunc', [15])
let &opfunc = string(Fn) LET &opfunc = string(Fn)
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
normal! g@l normal! g@l
call assert_equal([16, 'char'], g:OpFuncArgs) call assert_equal([15, 'char'], g:OpFuncArgs)
" Test for using a lambda function using set #" Test for using a lambda function using set
set opfunc={a\ ->\ MyopFunc(17,\ a)} VAR optval = "LSTART a LMIDDLE MyopFunc(16, a) LEND"
let g:OpFuncArgs = [] LET optval = substitute(optval, ' ', '\\ ', 'g')
normal! g@l exe "set opfunc=" .. optval
call assert_equal([17, 'char'], g:OpFuncArgs) LET g:OpFuncArgs = []
normal! g@l
call assert_equal([16, 'char'], g:OpFuncArgs)
" Test for using a lambda function using let #" Test for using a lambda function using LET
let &opfunc = {a -> MyopFunc(18, a)} LET &opfunc = LSTART a LMIDDLE MyopFunc(17, a) LEND
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
normal! g@l normal! g@l
call assert_equal([18, 'char'], g:OpFuncArgs) call assert_equal([17, 'char'], g:OpFuncArgs)
" Set 'operatorfunc' to a string(lambda expression) #" Set 'operatorfunc' to a string(lambda expression)
let &opfunc = '{a -> MyopFunc(19, a)}' LET &opfunc = 'LSTART a LMIDDLE MyopFunc(18, a) LEND'
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
normal! g@l normal! g@l
call assert_equal([19, 'char'], g:OpFuncArgs) call assert_equal([18, 'char'], g:OpFuncArgs)
" Set 'operatorfunc' to a variable with a lambda expression #" Set 'operatorfunc' to a variable with a lambda expression
let Lambda = {a -> MyopFunc(20, a)} VAR Lambda = LSTART a LMIDDLE MyopFunc(19, a) LEND
let &opfunc = Lambda LET &opfunc = Lambda
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
normal! g@l normal! g@l
call assert_equal([20, 'char'], g:OpFuncArgs) call assert_equal([19, 'char'], g:OpFuncArgs)
" Set 'operatorfunc' to a string(variable with a lambda expression) #" Set 'operatorfunc' to a string(variable with a lambda expression)
let Lambda = {a -> MyopFunc(21, a)} LET Lambda = LSTART a LMIDDLE MyopFunc(20, a) LEND
let &opfunc = string(Lambda) LET &opfunc = string(Lambda)
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
normal! g@l normal! g@l
call assert_equal([21, 'char'], g:OpFuncArgs) call assert_equal([20, 'char'], g:OpFuncArgs)
" Try to use 'operatorfunc' after the function is deleted #" Try to use 'operatorfunc' after the function is deleted
func TmpOpFunc(type) func g:TmpOpFunc(type)
let g:OpFuncArgs = [22, a:type] LET g:OpFuncArgs = [21, a:type]
endfunc endfunc
let &opfunc = function('TmpOpFunc') LET &opfunc = function('g:TmpOpFunc')
delfunc TmpOpFunc delfunc g:TmpOpFunc
call test_garbagecollect_now() call test_garbagecollect_now()
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
call assert_fails('normal! g@l', 'E117:') call assert_fails('normal! g@l', 'E117:')
call assert_equal([], g:OpFuncArgs) call assert_equal([], g:OpFuncArgs)
" Try to use a function with two arguments for 'operatorfunc' #" Try to use a function with two arguments for 'operatorfunc'
func! MyopFunc2(x, y) func MyopFunc2(x, y)
let g:OpFuncArgs = [a:x, a:y] LET g:OpFuncArgs = [a:x, a:y]
endfunc endfunc
set opfunc=MyopFunc2 set opfunc=MyopFunc2
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
call assert_fails('normal! g@l', 'E119:') call assert_fails('normal! g@l', 'E119:')
call assert_equal([], g:OpFuncArgs) call assert_equal([], g:OpFuncArgs)
" Try to use a lambda function with two arguments for 'operatorfunc' #" Try to use a lambda function with two arguments for 'operatorfunc'
let &opfunc = {a, b -> MyopFunc(23, b)} LET &opfunc = LSTART a, b LMIDDLE MyopFunc(22, b) LEND
let g:OpFuncArgs = [] LET g:OpFuncArgs = []
call assert_fails('normal! g@l', 'E119:') call assert_fails('normal! g@l', 'E119:')
call assert_equal([], g:OpFuncArgs) call assert_equal([], g:OpFuncArgs)
" Test for clearing the 'operatorfunc' option #" Test for clearing the 'operatorfunc' option
set opfunc='' set opfunc=''
set opfunc& set opfunc&
call assert_fails("set opfunc=function('abc')", "E700:")
call assert_fails("set opfunc=funcref('abc')", "E700:")
call assert_fails("set opfunc=function('abc')", "E700:") #" set 'operatorfunc' to a non-existing function
call assert_fails("set opfunc=funcref('abc')", "E700:") LET &opfunc = function('g:MyopFunc', [23])
call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:')
call assert_fails("LET &opfunc = function('NonExistingFunc')", 'E700:')
LET g:OpFuncArgs = []
normal! g@l
call assert_equal([23, 'char'], g:OpFuncArgs)
END
call CheckTransLegacySuccess(lines)
" Using Vim9 lambda expression in legacy context should fail " Using Vim9 lambda expression in legacy context should fail
set opfunc=(a)\ =>\ MyopFunc(24,\ a) set opfunc=(a)\ =>\ MyopFunc(24,\ a)
@@ -559,19 +571,24 @@ func Test_opfunc_callback()
call assert_fails('normal! g@l', 'E117:') call assert_fails('normal! g@l', 'E117:')
call assert_equal([], g:OpFuncArgs) call assert_equal([], g:OpFuncArgs)
" set 'operatorfunc' to a non-existing function " set 'operatorfunc' to a partial with dict. This used to cause a crash.
let &opfunc = function('MyopFunc', [25]) func SetOpFunc()
call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:') let operator = {'execute': function('OperatorExecute')}
call assert_fails("let &opfunc = function('NonExistingFunc')", 'E700:') let &opfunc = operator.execute
let g:OpFuncArgs = [] endfunc
normal! g@l func OperatorExecute(_) dict
call assert_equal([25, 'char'], g:OpFuncArgs) endfunc
call SetOpFunc()
call test_garbagecollect_now()
set operatorfunc=
delfunc SetOpFunc
delfunc OperatorExecute
" Vim9 tests " Vim9 tests
let lines =<< trim END let lines =<< trim END
vim9script vim9script
# Test for using function() # Test for using a def function with opfunc
def g:Vim9opFunc(val: number, type: string): void def g:Vim9opFunc(val: number, type: string): void
g:OpFuncArgs = [val, type] g:OpFuncArgs = [val, type]
enddef enddef
@@ -579,33 +596,6 @@ func Test_opfunc_callback()
g:OpFuncArgs = [] g:OpFuncArgs = []
normal! g@l normal! g@l
assert_equal([60, 'char'], g:OpFuncArgs) assert_equal([60, 'char'], g:OpFuncArgs)
# Test for using a lambda
&opfunc = (a) => Vim9opFunc(61, a)
g:OpFuncArgs = []
normal! g@l
assert_equal([61, 'char'], g:OpFuncArgs)
# Test for using a string(lambda)
&opfunc = '(a) => Vim9opFunc(62, a)'
g:OpFuncArgs = []
normal! g@l
assert_equal([62, 'char'], g:OpFuncArgs)
# Test for using a variable with a lambda expression
var Fn: func = (a) => Vim9opFunc(63, a)
&opfunc = Fn
g:OpFuncArgs = []
normal! g@l
assert_equal([63, 'char'], g:OpFuncArgs)
# Test for using a string(variable with a lambda expression)
Fn = (a) => Vim9opFunc(64, a)
&opfunc = string(Fn)
g:OpFuncArgs = []
normal! g@l
assert_equal([64, 'char'], g:OpFuncArgs)
bw!
END END
call CheckScriptSuccess(lines) call CheckScriptSuccess(lines)

View File

@@ -1,6 +1,7 @@
" Test for the quickfix feature. " Test for the quickfix feature.
source check.vim source check.vim
source vim9.vim
CheckFeature quickfix CheckFeature quickfix
source screendump.vim source screendump.vim
@@ -5282,6 +5283,131 @@ func Test_qftextfunc()
call Xtest_qftextfunc('l') call Xtest_qftextfunc('l')
endfunc endfunc
func Test_qftextfunc_callback()
let lines =<< trim END
set efm=%f:%l:%c:%m
#" Test for using a function()
set qftf=function('g:Tqfexpr')
cexpr "F1:1:1:L1"
copen
call assert_equal('F1-L1C1-L1', getline(1))
cclose
#" Using a funcref variable to set 'quickfixtextfunc'
VAR Fn = function('g:Tqfexpr')
LET &qftf = Fn
cexpr "F2:2:2:L2"
copen
call assert_equal('F2-L2C2-L2', getline(1))
cclose
#" Using string(funcref_variable) to set 'quickfixtextfunc'
LET Fn = function('g:Tqfexpr')
LET &qftf = string(Fn)
cexpr "F3:3:3:L3"
copen
call assert_equal('F3-L3C3-L3', getline(1))
cclose
#" Test for using a funcref()
set qftf=funcref('g:Tqfexpr')
cexpr "F4:4:4:L4"
copen
call assert_equal('F4-L4C4-L4', getline(1))
cclose
#" Using a funcref variable to set 'quickfixtextfunc'
LET Fn = funcref('g:Tqfexpr')
LET &qftf = Fn
cexpr "F5:5:5:L5"
copen
call assert_equal('F5-L5C5-L5', getline(1))
cclose
#" Using a string(funcref_variable) to set 'quickfixtextfunc'
LET Fn = funcref('g:Tqfexpr')
LET &qftf = string(Fn)
cexpr "F5:5:5:L5"
copen
call assert_equal('F5-L5C5-L5', getline(1))
cclose
#" Test for using a lambda function with set
VAR optval = "LSTART a LMIDDLE Tqfexpr(a) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set qftf=" .. optval
cexpr "F6:6:6:L6"
copen
call assert_equal('F6-L6C6-L6', getline(1))
cclose
#" Set 'quickfixtextfunc' to a lambda expression
LET &qftf = LSTART a LMIDDLE Tqfexpr(a) LEND
cexpr "F7:7:7:L7"
copen
call assert_equal('F7-L7C7-L7', getline(1))
cclose
#" Set 'quickfixtextfunc' to string(lambda_expression)
LET &qftf = "LSTART a LMIDDLE Tqfexpr(a) LEND"
cexpr "F8:8:8:L8"
copen
call assert_equal('F8-L8C8-L8', getline(1))
cclose
#" Set 'quickfixtextfunc' to a variable with a lambda expression
VAR Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND
LET &qftf = Lambda
cexpr "F9:9:9:L9"
copen
call assert_equal('F9-L9C9-L9', getline(1))
cclose
#" Set 'quickfixtextfunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND
LET &qftf = string(Lambda)
cexpr "F9:9:9:L9"
copen
call assert_equal('F9-L9C9-L9', getline(1))
cclose
END
call CheckLegacyAndVim9Success(lines)
" set 'quickfixtextfunc' to a partial with dict. This used to cause a crash.
func SetQftfFunc()
let params = {'qftf': function('g:DictQftfFunc')}
let &quickfixtextfunc = params.qftf
endfunc
func g:DictQftfFunc(_) dict
endfunc
call SetQftfFunc()
new
call SetQftfFunc()
bw
call test_garbagecollect_now()
new
set qftf=
wincmd w
set qftf=
:%bw!
" set per-quickfix list 'quickfixtextfunc' to a partial with dict. This used
" to cause a crash.
let &qftf = ''
func SetLocalQftfFunc()
let params = {'qftf': function('g:DictQftfFunc')}
call setqflist([], 'a', {'quickfixtextfunc' : params.qftf})
endfunc
call SetLocalQftfFunc()
call test_garbagecollect_now()
call setqflist([], 'a', {'quickfixtextfunc' : ''})
delfunc g:DictQftfFunc
delfunc SetQftfFunc
delfunc SetLocalQftfFunc
set efm&
endfunc
" Test for updating a location list for some other window and check that " Test for updating a location list for some other window and check that
" 'qftextfunc' uses the correct location list. " 'qftextfunc' uses the correct location list.
func Test_qftextfunc_other_loclist() func Test_qftextfunc_other_loclist()

View File

@@ -132,55 +132,121 @@ func Test_tagfunc_callback()
return v:null return v:null
endfunc endfunc
" Test for using a function() let lines =<< trim END
set tagfunc=function('MytagFunc1',[10]) #" Test for using a function()
new | only set tagfunc=function('g:MytagFunc1',\ [10])
let g:MytagFunc1_args = [] new | only
call assert_fails('tag a11', 'E433:') LET g:MytagFunc1_args = []
call assert_equal([10, 'a11', '', {}], g:MytagFunc1_args) call assert_fails('tag a11', 'E433:')
call assert_equal([10, 'a11', '', {}], g:MytagFunc1_args)
" Using a funcref variable to set 'tagfunc' #" Using a funcref variable to set 'tagfunc'
let Fn = function('MytagFunc1', [11]) VAR Fn = function('g:MytagFunc1', [11])
let &tagfunc = Fn LET &tagfunc = Fn
new | only new | only
let g:MytagFunc1_args = [] LET g:MytagFunc1_args = []
call assert_fails('tag a12', 'E433:') call assert_fails('tag a12', 'E433:')
call assert_equal([11, 'a12', '', {}], g:MytagFunc1_args) call assert_equal([11, 'a12', '', {}], g:MytagFunc1_args)
" Using a string(funcref_variable) to set 'tagfunc' #" Using a string(funcref_variable) to set 'tagfunc'
let Fn = function('MytagFunc1', [12]) LET Fn = function('g:MytagFunc1', [12])
let &tagfunc = string(Fn) LET &tagfunc = string(Fn)
new | only new | only
let g:MytagFunc1_args = [] LET g:MytagFunc1_args = []
call assert_fails('tag a12', 'E433:') call assert_fails('tag a12', 'E433:')
call assert_equal([12, 'a12', '', {}], g:MytagFunc1_args) call assert_equal([12, 'a12', '', {}], g:MytagFunc1_args)
" Test for using a funcref() #" Test for using a funcref()
func MytagFunc2(pat, flags, info) set tagfunc=funcref('g:MytagFunc1',\ [13])
let g:MytagFunc2_args = [a:pat, a:flags, a:info] new | only
return v:null LET g:MytagFunc1_args = []
endfunc call assert_fails('tag a13', 'E433:')
set tagfunc=funcref('MytagFunc1',[13]) call assert_equal([13, 'a13', '', {}], g:MytagFunc1_args)
new | only
let g:MytagFunc1_args = []
call assert_fails('tag a13', 'E433:')
call assert_equal([13, 'a13', '', {}], g:MytagFunc1_args)
" Using a funcref variable to set 'tagfunc' #" Using a funcref variable to set 'tagfunc'
let Fn = funcref('MytagFunc1', [14]) LET Fn = funcref('g:MytagFunc1', [14])
let &tagfunc = Fn LET &tagfunc = Fn
new | only new | only
let g:MytagFunc1_args = [] LET g:MytagFunc1_args = []
call assert_fails('tag a14', 'E433:') call assert_fails('tag a14', 'E433:')
call assert_equal([14, 'a14', '', {}], g:MytagFunc1_args) call assert_equal([14, 'a14', '', {}], g:MytagFunc1_args)
" Using a string(funcref_variable) to set 'tagfunc' #" Using a string(funcref_variable) to set 'tagfunc'
let Fn = funcref('MytagFunc1', [15]) LET Fn = funcref('g:MytagFunc1', [15])
let &tagfunc = string(Fn) LET &tagfunc = string(Fn)
new | only
LET g:MytagFunc1_args = []
call assert_fails('tag a14', 'E433:')
call assert_equal([15, 'a14', '', {}], g:MytagFunc1_args)
#" Test for using a lambda function
VAR optval = "LSTART a, b, c LMIDDLE MytagFunc1(16, a, b, c) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set tagfunc=" .. optval
new | only
LET g:MytagFunc1_args = []
call assert_fails('tag a17', 'E433:')
call assert_equal([16, 'a17', '', {}], g:MytagFunc1_args)
#" Set 'tagfunc' to a lambda expression
LET &tagfunc = LSTART a, b, c LMIDDLE MytagFunc1(17, a, b, c) LEND
new | only
LET g:MytagFunc1_args = []
call assert_fails('tag a18', 'E433:')
call assert_equal([17, 'a18', '', {}], g:MytagFunc1_args)
#" Set 'tagfunc' to a string(lambda expression)
LET &tagfunc = 'LSTART a, b, c LMIDDLE MytagFunc1(18, a, b, c) LEND'
new | only
LET g:MytagFunc1_args = []
call assert_fails('tag a18', 'E433:')
call assert_equal([18, 'a18', '', {}], g:MytagFunc1_args)
#" Set 'tagfunc' to a variable with a lambda expression
VAR Lambda = LSTART a, b, c LMIDDLE MytagFunc1(19, a, b, c) LEND
LET &tagfunc = Lambda
new | only
LET g:MytagFunc1_args = []
call assert_fails("tag a19", "E433:")
call assert_equal([19, 'a19', '', {}], g:MytagFunc1_args)
#" Set 'tagfunc' to a string(variable with a lambda expression)
LET Lambda = LSTART a, b, c LMIDDLE MytagFunc1(20, a, b, c) LEND
LET &tagfunc = string(Lambda)
new | only
LET g:MytagFunc1_args = []
call assert_fails("tag a19", "E433:")
call assert_equal([20, 'a19', '', {}], g:MytagFunc1_args)
#" Test for using a lambda function with incorrect return value
LET Lambda = LSTART a, b, c LMIDDLE strlen(a) LEND
LET &tagfunc = string(Lambda)
new | only
call assert_fails("tag a20", "E987:")
#" Test for clearing the 'tagfunc' option
set tagfunc=''
set tagfunc&
call assert_fails("set tagfunc=function('abc')", "E700:")
call assert_fails("set tagfunc=funcref('abc')", "E700:")
#" set 'tagfunc' to a non-existing function
LET &tagfunc = function('g:MytagFunc1', [21])
call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:')
call assert_fails("LET &tagfunc = function('NonExistingFunc')", 'E700:')
call assert_fails("tag axb123", 'E426:')
END
call CheckLegacyAndVim9Success(lines)
let &tagfunc = "{a -> 'abc'}"
call assert_fails("echo taglist('a')", "E987:")
" Using Vim9 lambda expression in legacy context should fail
set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc1(21,\ a,\ b,\ c)
new | only new | only
let g:MytagFunc1_args = [] let g:MytagFunc1_args = []
call assert_fails('tag a14', 'E433:') call assert_fails("tag a17", "E117:")
call assert_equal([15, 'a14', '', {}], g:MytagFunc1_args) call assert_equal([], g:MytagFunc1_args)
" Test for using a script local function " Test for using a script local function
set tagfunc=<SID>ScriptLocalTagFunc set tagfunc=<SID>ScriptLocalTagFunc
@@ -205,70 +271,25 @@ func Test_tagfunc_callback()
call assert_fails('tag a16', 'E433:') call assert_fails('tag a16', 'E433:')
call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs) call assert_equal(['a16', '', {}], g:ScriptLocalFuncArgs)
" Test for using a lambda function " set 'tagfunc' to a partial with dict. This used to cause a crash.
set tagfunc={a,\ b,\ c\ ->\ MytagFunc1(16,\ a,\ b,\ c)} func SetTagFunc()
new | only let params = {'tagfn': function('g:DictTagFunc')}
let g:MytagFunc1_args = [] let &tagfunc = params.tagfn
call assert_fails('tag a17', 'E433:') endfunc
call assert_equal([16, 'a17', '', {}], g:MytagFunc1_args) func g:DictTagFunc(_) dict
endfunc
" Set 'tagfunc' to a lambda expression call SetTagFunc()
let &tagfunc = {a, b, c -> MytagFunc1(17, a, b, c)} new
new | only call SetTagFunc()
let g:MytagFunc1_args = [] bw
call assert_fails('tag a18', 'E433:') call test_garbagecollect_now()
call assert_equal([17, 'a18', '', {}], g:MytagFunc1_args) new
set tagfunc=
" Set 'tagfunc' to a string(lambda expression) wincmd w
let &tagfunc = '{a, b, c -> MytagFunc1(18, a, b, c)}' set tagfunc=
new | only :%bw!
let g:MytagFunc1_args = [] delfunc g:DictTagFunc
call assert_fails('tag a18', 'E433:') delfunc SetTagFunc
call assert_equal([18, 'a18', '', {}], g:MytagFunc1_args)
" Set 'tagfunc' to a variable with a lambda expression
let Lambda = {a, b, c -> MytagFunc1(19, a, b, c)}
let &tagfunc = Lambda
new | only
let g:MytagFunc1_args = []
call assert_fails("tag a19", "E433:")
call assert_equal([19, 'a19', '', {}], g:MytagFunc1_args)
" Set 'tagfunc' to a string(variable with a lambda expression)
let Lambda = {a, b, c -> MytagFunc1(20, a, b, c)}
let &tagfunc = string(Lambda)
new | only
let g:MytagFunc1_args = []
call assert_fails("tag a19", "E433:")
call assert_equal([20, 'a19', '', {}], g:MytagFunc1_args)
" Test for using a lambda function with incorrect return value
let Lambda = {s -> strlen(s)}
let &tagfunc = string(Lambda)
new | only
call assert_fails("tag a20", "E987:")
" Test for clearing the 'tagfunc' option
set tagfunc=''
set tagfunc&
call assert_fails("set tagfunc=function('abc')", "E700:")
call assert_fails("set tagfunc=funcref('abc')", "E700:")
let &tagfunc = "{a -> 'abc'}"
call assert_fails("echo taglist('a')", "E987:")
" Using Vim9 lambda expression in legacy context should fail
set tagfunc=(a,\ b,\ c)\ =>\ g:MytagFunc1(21,\ a,\ b,\ c)
new | only
let g:MytagFunc1_args = []
call assert_fails("tag a17", "E117:")
call assert_equal([], g:MytagFunc1_args)
" set 'tagfunc' to a non-existing function
call assert_fails("set tagfunc=function('NonExistingFunc')", 'E700:')
call assert_fails("let &tagfunc = function('NonExistingFunc')", 'E700:')
call assert_fails("tag axb123", 'E426:')
bw!
" Vim9 tests " Vim9 tests
let lines =<< trim END let lines =<< trim END
@@ -284,42 +305,11 @@ func Test_tagfunc_callback()
g:Vim9tagFuncArgs = [] g:Vim9tagFuncArgs = []
assert_fails('tag a10', 'E433:') assert_fails('tag a10', 'E433:')
assert_equal([60, 'a10', '', {}], g:Vim9tagFuncArgs) assert_equal([60, 'a10', '', {}], g:Vim9tagFuncArgs)
# Test for using a lambda
&tagfunc = (a, b, c) => MytagFunc1(61, a, b, c)
new | only
g:MytagFunc1_args = []
assert_fails('tag a20', 'E433:')
assert_equal([61, 'a20', '', {}], g:MytagFunc1_args)
# Test for using a string(lambda)
&tagfunc = '(a, b, c) => MytagFunc1(62, a, b, c)'
new | only
g:MytagFunc1_args = []
assert_fails('tag a20', 'E433:')
assert_equal([62, 'a20', '', {}], g:MytagFunc1_args)
# Test for using a variable with a lambda expression
var Fn: func = (a, b, c) => MytagFunc1(63, a, b, c)
&tagfunc = Fn
new | only
g:MytagFunc1_args = []
assert_fails('tag a30', 'E433:')
assert_equal([63, 'a30', '', {}], g:MytagFunc1_args)
# Test for using a variable with a lambda expression
Fn = (a, b, c) => MytagFunc1(64, a, b, c)
&tagfunc = string(Fn)
new | only
g:MytagFunc1_args = []
assert_fails('tag a30', 'E433:')
assert_equal([64, 'a30', '', {}], g:MytagFunc1_args)
END END
call CheckScriptSuccess(lines) call CheckScriptSuccess(lines)
" cleanup " cleanup
delfunc MytagFunc1 delfunc MytagFunc1
delfunc MytagFunc2
set tagfunc& set tagfunc&
%bw! %bw!
endfunc endfunc

View File

@@ -753,6 +753,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
3788,
/**/ /**/
3787, 3787,
/**/ /**/