mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 9.0.0836: wrong error when using extend() with funcref
Problem: Wrong error when using extend() with funcref. Solution: Better check the variable type. (closes #11468, closes #11455)
This commit is contained in:
17
src/dict.c
17
src/dict.c
@@ -352,7 +352,7 @@ dict_copy(dict_T *orig, int deep, int top, int copyID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for adding a function to g: or s:.
|
* Check for adding a function to g: or s: (in Vim9 script) or l:.
|
||||||
* If the name is wrong give an error message and return TRUE.
|
* If the name is wrong give an error message and return TRUE.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@@ -1105,17 +1105,9 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action, char *func_name)
|
|||||||
{
|
{
|
||||||
--todo;
|
--todo;
|
||||||
di1 = dict_find(d1, hi2->hi_key, -1);
|
di1 = dict_find(d1, hi2->hi_key, -1);
|
||||||
if (d1->dv_scope != 0)
|
// Check the key to be valid when adding to any scope.
|
||||||
{
|
if (d1->dv_scope != 0 && !valid_varname(hi2->hi_key, -1, TRUE))
|
||||||
// Disallow replacing a builtin function in l: and g:.
|
break;
|
||||||
// Check the key to be valid when adding to any scope.
|
|
||||||
if (d1->dv_scope == VAR_DEF_SCOPE
|
|
||||||
&& HI2DI(hi2)->di_tv.v_type == VAR_FUNC
|
|
||||||
&& var_wrong_func_name(hi2->hi_key, di1 == NULL))
|
|
||||||
break;
|
|
||||||
if (!valid_varname(hi2->hi_key, -1, TRUE))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type != NULL
|
if (type != NULL
|
||||||
&& check_typval_arg_type(type, &HI2DI(hi2)->di_tv,
|
&& check_typval_arg_type(type, &HI2DI(hi2)->di_tv,
|
||||||
@@ -1138,6 +1130,7 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action, char *func_name)
|
|||||||
if (value_check_lock(di1->di_tv.v_lock, arg_errmsg, TRUE)
|
if (value_check_lock(di1->di_tv.v_lock, arg_errmsg, TRUE)
|
||||||
|| var_check_ro(di1->di_flags, arg_errmsg, TRUE))
|
|| var_check_ro(di1->di_flags, arg_errmsg, TRUE))
|
||||||
break;
|
break;
|
||||||
|
// Disallow replacing a builtin function.
|
||||||
if (dict_wrong_func_name(d1, &HI2DI(hi2)->di_tv, hi2->hi_key))
|
if (dict_wrong_func_name(d1, &HI2DI(hi2)->di_tv, hi2->hi_key))
|
||||||
break;
|
break;
|
||||||
clear_tv(&di1->di_tv);
|
clear_tv(&di1->di_tv);
|
||||||
|
@@ -1376,7 +1376,8 @@ get_lval(
|
|||||||
else
|
else
|
||||||
prevval = 0; // avoid compiler warning
|
prevval = 0; // avoid compiler warning
|
||||||
wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE
|
wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE
|
||||||
&& rettv->v_type == VAR_FUNC
|
&& (rettv->v_type == VAR_FUNC
|
||||||
|
|| rettv->v_type == VAR_PARTIAL)
|
||||||
&& var_wrong_func_name(key, lp->ll_di == NULL))
|
&& var_wrong_func_name(key, lp->ll_di == NULL))
|
||||||
|| !valid_varname(key, -1, TRUE);
|
|| !valid_varname(key, -1, TRUE);
|
||||||
if (len != -1)
|
if (len != -1)
|
||||||
|
@@ -2938,6 +2938,25 @@ func Test_builtin_check()
|
|||||||
let g:bar = 123
|
let g:bar = 123
|
||||||
call extend(g:, #{bar: { -> "foo" }}, "keep")
|
call extend(g:, #{bar: { -> "foo" }}, "keep")
|
||||||
call assert_fails('call extend(g:, #{bar: { -> "foo" }}, "force")', 'E704:')
|
call assert_fails('call extend(g:, #{bar: { -> "foo" }}, "force")', 'E704:')
|
||||||
|
unlet g:bar
|
||||||
|
|
||||||
|
call assert_fails('call extend(l:, #{foo: { -> "foo" }})', 'E704:')
|
||||||
|
let bar = 123
|
||||||
|
call extend(l:, #{bar: { -> "foo" }}, "keep")
|
||||||
|
call assert_fails('call extend(l:, #{bar: { -> "foo" }}, "force")', 'E704:')
|
||||||
|
unlet bar
|
||||||
|
|
||||||
|
call assert_fails('call extend(g:, #{foo: function("extend")})', 'E704:')
|
||||||
|
let g:bar = 123
|
||||||
|
call extend(g:, #{bar: function("extend")}, "keep")
|
||||||
|
call assert_fails('call extend(g:, #{bar: function("extend")}, "force")', 'E704:')
|
||||||
|
unlet g:bar
|
||||||
|
|
||||||
|
call assert_fails('call extend(l:, #{foo: function("extend")})', 'E704:')
|
||||||
|
let bar = 123
|
||||||
|
call extend(l:, #{bar: function("extend")}, "keep")
|
||||||
|
call assert_fails('call extend(l:, #{bar: function("extend")}, "force")', 'E704:')
|
||||||
|
unlet bar
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_funcref_to_string()
|
func Test_funcref_to_string()
|
||||||
|
@@ -316,6 +316,7 @@ func Test_let_errors()
|
|||||||
call assert_fails('let l += 2', 'E734:')
|
call assert_fails('let l += 2', 'E734:')
|
||||||
call assert_fails('let g:["a;b"] = 10', 'E461:')
|
call assert_fails('let g:["a;b"] = 10', 'E461:')
|
||||||
call assert_fails('let g:.min = function("max")', 'E704:')
|
call assert_fails('let g:.min = function("max")', 'E704:')
|
||||||
|
call assert_fails('let g:cos = "" | let g:.cos = {-> 42}', 'E704:')
|
||||||
if has('channel')
|
if has('channel')
|
||||||
let ch = test_null_channel()
|
let ch = test_null_channel()
|
||||||
call assert_fails('let ch += 1', 'E734:')
|
call assert_fails('let ch += 1', 'E734:')
|
||||||
|
@@ -695,6 +695,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 */
|
||||||
|
/**/
|
||||||
|
836,
|
||||||
/**/
|
/**/
|
||||||
835,
|
835,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user