From 7683199a9bf5d84745a10222feddc43343410068 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 28 Oct 2022 11:53:22 +0800 Subject: [PATCH] vim-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 vim/vim#8302) https://github.com/vim/vim/commit/3d9c4eefe656ee8bf58c0496a48bd56bac180056 Cherry-pick Test_gettext() from patch 8.2.2886. --- src/nvim/eval.c | 7 +++++++ src/nvim/testdir/test_functions.vim | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 465d76de69..5b5b4d259c 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1760,6 +1760,13 @@ void set_var_lval(lval_T *lp, char *endp, typval_T *rettv, int copy, const bool semsg(_(e_dictkey), lp->ll_newkey); return; } + if ((lp->ll_tv->vval.v_dict == &globvardict + // || 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 = tv_dict_item_alloc((const char *)lp->ll_newkey); diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index d2603809b9..afeea20f2d 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -2478,4 +2478,17 @@ func Test_default_arg_value() call assert_equal('msg', HasDefault()) endfunc +" Test for gettext() +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