summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-05-31 22:15:26 +0200
committerBram Moolenaar <Bram@vim.org>2021-05-31 22:15:26 +0200
commit3d9c4eefe656ee8bf58c0496a48bd56bac180056 (patch)
tree4fcbd581c3c5d8ff4282357b589367155a2b5680
parentbb162367ac77db877586086d7456685f2aeb8754 (diff)
downloadvim-git-3d9c4eefe656ee8bf58c0496a48bd56bac180056.tar.gz
patch 8.2.2918: builtin function can be shadowed by global variablev8.2.2918
Problem: Builtin function can be shadowed by global variable. Solution: Check for builtin function before variable. (Yasuhiro Matsumoto, closes #8302)
-rw-r--r--src/eval.c7
-rw-r--r--src/testdir/test_functions.vim8
-rw-r--r--src/version.c2
3 files changed, 17 insertions, 0 deletions
diff --git a/src/eval.c b/src/eval.c
index 8e5543549..9fb3b4e2c 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1462,6 +1462,13 @@ set_var_lval(
semsg(_(e_dictkey), lp->ll_newkey);
return;
}
+ if ((lp->ll_tv->vval.v_dict == get_globvar_dict()
+ || lp->ll_tv->vval.v_dict ==
+ &SCRIPT_ITEM(current_sctx.sc_sid)->sn_vars->sv_dict)
+ && (rettv->v_type == VAR_FUNC
+ || rettv->v_type == VAR_PARTIAL)
+ && var_wrong_func_name(lp->ll_newkey, TRUE))
+ return;
// Need to add an item to the Dictionary.
di = dictitem_alloc(lp->ll_newkey);
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index 433760658..e1aff6137 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -2681,4 +2681,12 @@ func Test_gettext()
call assert_fails('call gettext(1)', 'E475:')
endfunc
+func Test_builtin_check()
+ call assert_fails('let g:["trim"] = {x -> " " .. x}', 'E704:')
+ call assert_fails('let g:.trim = {x -> " " .. x}', 'E704:')
+ call assert_fails('let s:["trim"] = {x -> " " .. x}', 'E704:')
+ call assert_fails('let s:.trim = {x -> " " .. x}', 'E704:')
+endfunc
+
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 099d05a56..c1fdb649d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2918,
+/**/
2917,
/**/
2916,