]> granicus.if.org Git - vim/commitdiff
patch 8.2.2918: builtin function can be shadowed by global variable v8.2.2918
authorBram Moolenaar <Bram@vim.org>
Mon, 31 May 2021 20:15:26 +0000 (22:15 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 31 May 2021 20:15:26 +0000 (22:15 +0200)
Problem:    Builtin function can be shadowed by global variable.
Solution:   Check for builtin function before variable. (Yasuhiro Matsumoto,
            closes #8302)

src/eval.c
src/testdir/test_functions.vim
src/version.c

index 8e554354965ea8d310a5a8a7ec216ce8b30f2b31..9fb3b4e2ca69f85e333d6cfadddbc3ae45b394e6 100644 (file)
@@ -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);
index 433760658484814dfac0f96923c66e1255dca372..e1aff6137d25dcbda6b42371593a6660f54447b7 100644 (file)
@@ -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
index 099d05a567674140459f16ca5262a49368e0aac7..c1fdb649d4c24f90ec937aaafe06072db97eccc3 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2918,
 /**/
     2917,
 /**/