Skip to content

Commit 3d9c4ee

Browse files
committed
patch 8.2.2918: builtin function can be shadowed by global variable
Problem: Builtin function can be shadowed by global variable. Solution: Check for builtin function before variable. (Yasuhiro Matsumoto, closes #8302)
1 parent bb16236 commit 3d9c4ee

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/eval.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,13 @@ set_var_lval(
14621462
semsg(_(e_dictkey), lp->ll_newkey);
14631463
return;
14641464
}
1465+
if ((lp->ll_tv->vval.v_dict == get_globvar_dict()
1466+
|| lp->ll_tv->vval.v_dict ==
1467+
&SCRIPT_ITEM(current_sctx.sc_sid)->sn_vars->sv_dict)
1468+
&& (rettv->v_type == VAR_FUNC
1469+
|| rettv->v_type == VAR_PARTIAL)
1470+
&& var_wrong_func_name(lp->ll_newkey, TRUE))
1471+
return;
14651472

14661473
// Need to add an item to the Dictionary.
14671474
di = dictitem_alloc(lp->ll_newkey);

src/testdir/test_functions.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,4 +2681,12 @@ func Test_gettext()
26812681
call assert_fails('call gettext(1)', 'E475:')
26822682
endfunc
26832683

2684+
func Test_builtin_check()
2685+
call assert_fails('let g:["trim"] = {x -> " " .. x}', 'E704:')
2686+
call assert_fails('let g:.trim = {x -> " " .. x}', 'E704:')
2687+
call assert_fails('let s:["trim"] = {x -> " " .. x}', 'E704:')
2688+
call assert_fails('let s:.trim = {x -> " " .. x}', 'E704:')
2689+
endfunc
2690+
2691+
26842692
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2918,
753755
/**/
754756
2917,
755757
/**/

0 commit comments

Comments
 (0)