Compare commits

...

7 Commits

Author SHA1 Message Date
Bram Moolenaar
c77534c303 patch 8.2.2005: redoing a mapping with <Cmd> doesn't work properly
Problem:    Redoing a mapping with <Cmd> doesn't work properly.
Solution:   Fill the redo buffer.  Use "<SNR>" instead of a key code.
            (closes #7282)
2020-11-18 11:34:37 +01:00
Bram Moolenaar
b3a01946b3 patch 8.2.2004: compiler warning for uninitialized variable
Problem:    Compiler warning for uninitialized variable.
Solution:   Initialize "ufunc". (John Marriott)
2020-11-17 19:56:09 +01:00
Bram Moolenaar
1efefda623 patch 8.2.2003: build error with +conceal but without +popupwin
Problem:    Build error with +conceal but without +popupwin.
Solution:   Add #ifdef. (Tom Ryder, closes #7316)
2020-11-17 19:22:06 +01:00
Bram Moolenaar
52bf81c2d5 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Problem:    Vim9: lambda argument shadowed by function name.
Solution:   Let function name be shadowed by lambda argument. (closes #7313)
2020-11-17 18:50:44 +01:00
Bram Moolenaar
0ba48e8c27 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Problem:    Vim9: :def function does not apply 'maxfuncdepth'.
Solution:   Use 'maxfuncdepth'. (issue #7313)
2020-11-17 18:23:19 +01:00
Bram Moolenaar
fc74d03e76 patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Problem:    Vim9: dict.key assignment not implemented yet.
Solution:   Implement dict.key assignment. (closes #7312)
2020-11-16 22:11:49 +01:00
Bram Moolenaar
e6329e4c55 patch 8.2.1999: terminal popup test sometimes fails
Problem:    Terminal popup test sometimes fails.
Solution:   Wait for the popup to close.
2020-11-16 21:10:34 +01:00
12 changed files with 213 additions and 39 deletions

View File

@@ -2446,16 +2446,18 @@ win_line(
&& conceal_cursor_line(wp)
&& (int)wp->w_virtcol <= vcol + n_skip)
{
# ifdef FEAT_RIGHTLEFT
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
wp->w_wcol = wp->w_width - col + boguscols - 1;
else
# endif
# endif
wp->w_wcol = col - boguscols;
wp->w_wrow = row;
did_wcol = TRUE;
curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
# ifdef FEAT_PROP_POPUP
curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
# endif
}
#endif

View File

@@ -3691,11 +3691,7 @@ getcmdkeycmd(
else if (IS_SPECIAL(c1))
{
if (c1 == K_SNR)
{
ga_append(&line_ga, (char)K_SPECIAL);
ga_append(&line_ga, (char)KS_EXTRA);
ga_append(&line_ga, (char)KE_SNR);
}
ga_concat(&line_ga, (char_u *)"<SNR>");
else
{
semsg(e_cmd_maping_must_not_include_str_key,

View File

@@ -3465,8 +3465,9 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
if ((redo_yank || oap->op_type != OP_YANK)
&& ((!VIsual_active || oap->motion_force)
// Also redo Operator-pending Visual mode mappings
|| (VIsual_active && cap->cmdchar == ':'
&& oap->op_type != OP_COLON))
|| (VIsual_active
&& (cap->cmdchar == ':' || cap->cmdchar == K_COMMAND)
&& oap->op_type != OP_COLON))
&& cap->cmdchar != 'D'
#ifdef FEAT_FOLDING
&& oap->op_type != OP_FOLD
@@ -3688,7 +3689,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
get_op_char(oap->op_type),
get_extra_op_char(oap->op_type),
oap->motion_force, cap->cmdchar, cap->nchar);
else if (cap->cmdchar != ':')
else if (cap->cmdchar != ':' && cap->cmdchar != K_COMMAND)
{
int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL;

View File

@@ -14,6 +14,10 @@ ufunc_T *find_func(char_u *name, int is_global, cctx_T *cctx);
int func_is_global(ufunc_T *ufunc);
int func_name_refcount(char_u *name);
void copy_func(char_u *lambda, char_u *global);
int funcdepth_increment(void);
void funcdepth_decrement(void);
int funcdepth_get(void);
void funcdepth_restore(int depth);
int call_user_func_check(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, funcexe_T *funcexe, dict_T *selfdict);
void save_funccal(funccal_entry_T *entry);
void restore_funccal(void);

View File

@@ -1324,4 +1324,40 @@ func Test_map_cmdkey_cmdline_mode()
%bw!
endfunc
func Test_map_cmdkey_redo()
func SelectDash()
call search('^---\n\zs', 'bcW')
norm! V
call search('\n\ze---$', 'W')
endfunc
let text =<< trim END
---
aaa
---
bbb
bbb
---
ccc
ccc
ccc
---
END
new Xcmdtext
call setline(1, text)
onoremap <silent> i- <Cmd>call SelectDash()<CR>
call feedkeys('2Gdi-', 'xt')
call assert_equal(['---', '---'], getline(1, 2))
call feedkeys('j.', 'xt')
call assert_equal(['---', '---', '---'], getline(1, 3))
call feedkeys('j.', 'xt')
call assert_equal(['---', '---', '---', '---'], getline(1, 4))
bwipe!
call delete('Xcmdtext')
delfunc SelectDash
ounmap i-
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -1249,8 +1249,8 @@ func Test_terminal_popup_bufload()
" must not have switched to another window
call assert_equal(winid, win_getid())
call feedkeys("exit\<CR>", 'xt')
sleep 50m
call StopShellInTerminal(termbuf)
call WaitFor({-> win_getid() != winid})
exe 'bwipe! ' .. newbuf
endfunc

View File

@@ -408,6 +408,15 @@ def Test_assignment_dict()
# overwrite
dict3['key'] = 'another'
assert_equal(dict3, #{key: 'another'})
dict3.key = 'yet another'
assert_equal(dict3, #{key: 'yet another'})
var lines =<< trim END
var dd = #{one: 1}
dd.one) = 2
END
CheckDefFailure(lines, 'E15:', 2)
# empty key can be used
var dd = {}
@@ -418,7 +427,7 @@ def Test_assignment_dict()
var somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'}
# assignment to script-local dict
var lines =<< trim END
lines =<< trim END
vim9script
var test: dict<any> = {}
def FillDict(): dict<any>

View File

@@ -49,6 +49,36 @@ def TestCompilingError()
call delete('XTest_compile_error')
enddef
def CallRecursive(n: number): number
return CallRecursive(n + 1)
enddef
def CallMapRecursive(l: list<number>): number
return map(l, {_, v -> CallMapRecursive([v])})[0]
enddef
def Test_funcdepth_error()
set maxfuncdepth=10
var caught = false
try
CallRecursive(1)
catch /E132:/
caught = true
endtry
assert_true(caught)
caught = false
try
CallMapRecursive([1])
catch /E132:/
caught = true
endtry
assert_true(caught)
set maxfuncdepth&
enddef
def ReturnString(): string
return 'string'
enddef
@@ -1426,6 +1456,15 @@ def Test_nested_lambda()
CheckScriptSuccess(lines)
enddef
def Shadowed(): list<number>
var FuncList: list<func: number> = [{ -> 42}]
return FuncList->map({_, Shadowed -> Shadowed()})
enddef
def Test_lambda_arg_shadows_func()
assert_equal([42], Shadowed())
enddef
def Line_continuation_in_def(dir: string = ''): string
var path: string = empty(dir)
\ ? 'empty'

View File

@@ -1373,6 +1373,50 @@ failed:
func_clear_free(fp, TRUE);
}
static int funcdepth = 0;
/*
* Increment the function call depth count.
* Return FAIL when going over 'maxfuncdepth'.
* Otherwise return OK, must call funcdepth_decrement() later!
*/
int
funcdepth_increment(void)
{
if (funcdepth >= p_mfd)
{
emsg(_("E132: Function call depth is higher than 'maxfuncdepth'"));
return FAIL;
}
++funcdepth;
return OK;
}
void
funcdepth_decrement(void)
{
--funcdepth;
}
/*
* Get the current function call depth.
*/
int
funcdepth_get(void)
{
return funcdepth;
}
/*
* Restore the function call depth. This is for cases where there is no
* garantee funcdepth_decrement() can be called exactly the same number of
* times as funcdepth_increment().
*/
void
funcdepth_restore(int depth)
{
funcdepth = depth;
}
/*
* Call a user function.
@@ -1391,7 +1435,6 @@ call_user_func(
funccall_T *fc;
int save_did_emsg;
int default_arg_err = FALSE;
static int depth = 0;
dictitem_T *v;
int fixvar_idx = 0; // index in fixvar[]
int i;
@@ -1406,15 +1449,13 @@ call_user_func(
#endif
ESTACK_CHECK_DECLARATION
// If depth of calling is getting too high, don't execute the function
if (depth >= p_mfd)
// If depth of calling is getting too high, don't execute the function.
if (funcdepth_increment() == FAIL)
{
emsg(_("E132: Function call depth is higher than 'maxfuncdepth'"));
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = -1;
return;
}
++depth;
line_breakcheck(); // check for CTRL-C hit
@@ -1437,7 +1478,7 @@ call_user_func(
{
// Execute the function, possibly compiling it first.
call_def_function(fp, argcount, argvars, funcexe->partial, rettv);
--depth;
funcdepth_decrement();
current_funccal = fc->caller;
free_funccal(fc);
return;
@@ -1783,8 +1824,7 @@ call_user_func(
}
did_emsg |= save_did_emsg;
--depth;
funcdepth_decrement();
cleanup_function_call(fc);
}

View File

@@ -750,6 +750,20 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2005,
/**/
2004,
/**/
2003,
/**/
2002,
/**/
2001,
/**/
2000,
/**/
1999,
/**/
1998,
/**/

View File

@@ -2626,7 +2626,7 @@ compile_call(
char_u fname_buf[FLEN_FIXED + 1];
char_u *tofree = NULL;
int error = FCERR_NONE;
ufunc_T *ufunc;
ufunc_T *ufunc = NULL;
int res = FAIL;
int is_autoload;
@@ -2712,13 +2712,19 @@ compile_call(
goto theend;
}
// If we can find the function by name generate the right call.
// Skip global functions here, a local funcref takes precedence.
ufunc = find_func(name, FALSE, cctx);
if (ufunc != NULL && !func_is_global(ufunc))
// An argument or local variable can be a function reference, this
// overrules a function name.
if (lookup_local(namebuf, varlen, cctx) == NULL
&& arg_exists(namebuf, varlen, NULL, NULL, NULL, cctx) != OK)
{
res = generate_CALL(cctx, ufunc, argcount);
goto theend;
// If we can find the function by name generate the right call.
// Skip global functions here, a local funcref takes precedence.
ufunc = find_func(name, FALSE, cctx);
if (ufunc != NULL && !func_is_global(ufunc))
{
res = generate_CALL(cctx, ufunc, argcount);
goto theend;
}
}
// If the name is a variable, load it and use PCALL.
@@ -5384,14 +5390,14 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
member_type = type;
if (var_end > var_start + varlen)
{
// Something follows after the variable: "var[idx]".
// Something follows after the variable: "var[idx]" or "var.key".
if (is_decl)
{
emsg(_(e_cannot_use_index_when_declaring_variable));
goto theend;
}
if (var_start[varlen] == '[')
if (var_start[varlen] == '[' || var_start[varlen] == '.')
{
has_index = TRUE;
if (type->tt_member == NULL)
@@ -5635,21 +5641,33 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
{
int r;
// Compile the "idx" in "var[idx]".
// Compile the "idx" in "var[idx]" or "key" in "var.key".
if (new_local)
--cctx->ctx_locals.ga_len;
p = skipwhite(var_start + varlen + 1);
r = compile_expr0(&p, cctx);
p = var_start + varlen;
if (*p == '[')
{
p = skipwhite(p + 1);
r = compile_expr0(&p, cctx);
if (r == OK && *skipwhite(p) != ']')
{
// this should not happen
emsg(_(e_missbrac));
r = FAIL;
}
}
else // if (*p == '.')
{
char_u *key_end = to_name_end(p + 1, TRUE);
char_u *key = vim_strnsave(p + 1, key_end - p - 1);
r = generate_PUSHS(cctx, key);
}
if (new_local)
++cctx->ctx_locals.ga_len;
if (r == FAIL)
goto theend;
if (*skipwhite(p) != ']')
{
// this should not happen
emsg(_(e_missbrac));
goto theend;
}
if (type == &t_any)
{
type_T *idx_type = ((type_T **)stack->ga_data)[

View File

@@ -227,6 +227,10 @@ call_dfunc(int cdf_idx, int argcount_arg, ectx_T *ectx)
== FAIL)
return FAIL;
// If depth of calling is getting too high, don't execute the function.
if (funcdepth_increment() == FAIL)
return FAIL;
// Move the vararg-list to below the missing optional arguments.
if (vararg_count > 0 && arg_to_add > 0)
*STACK_TV_BOT(arg_to_add - 1) = *STACK_TV_BOT(-1);
@@ -503,6 +507,7 @@ func_return(ectx_T *ectx)
ectx->ec_stack.ga_len = top + 1;
*STACK_TV_BOT(-1) = *STACK_TV(idx);
funcdepth_decrement();
return OK;
}
@@ -835,6 +840,7 @@ call_def_function(
cmdmod_T save_cmdmod;
int restore_cmdmod = FALSE;
int trylevel_at_start = trylevel;
int orig_funcdepth;
// Get pointer to item in the stack.
#define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx)
@@ -870,11 +876,19 @@ call_def_function(
}
}
// If depth of calling is getting too high, don't execute the function.
orig_funcdepth = funcdepth_get();
if (funcdepth_increment() == FAIL)
return FAIL;
CLEAR_FIELD(ectx);
ectx.ec_dfunc_idx = ufunc->uf_dfunc_idx;
ga_init2(&ectx.ec_stack, sizeof(typval_T), 500);
if (ga_grow(&ectx.ec_stack, 20) == FAIL)
{
funcdepth_decrement();
return FAIL;
}
ga_init2(&ectx.ec_trystack, sizeof(trycmd_T), 10);
ga_init2(&ectx.ec_funcrefs, sizeof(partial_T *), 10);
@@ -2941,6 +2955,7 @@ failed_early:
if (ret != OK && did_emsg == did_emsg_before)
semsg(_(e_unknown_error_while_executing_str),
printable_func_name(ufunc));
funcdepth_restore(orig_funcdepth);
return ret;
}