comparison src/userfunc.c @ 26504:7821550ba3a8 v8.2.3782

patch 8.2.3782: Vim9: no error if a function shadows a script variable Commit: https://github.com/vim/vim/commit/052ff291d72bc9c176f9562f021d7e8e030e74c0 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 11 13:54:46 2021 +0000 patch 8.2.3782: Vim9: no error if a function shadows a script variable Problem: Vim9: no error if a function shadows a script variable. Solution: Check the function doesn't shadow a variable. (closes https://github.com/vim/vim/issues/9310)
author Bram Moolenaar <Bram@vim.org>
date Sat, 11 Dec 2021 15:00:03 +0100
parents 65b4109a4297
children 4a1d2abc2016
comparison
equal deleted inserted replaced
26503:ae12de843776 26504:7821550ba3a8
4132 arg = fudi.fd_newkey; 4132 arg = fudi.fd_newkey;
4133 if (arg != NULL && (fudi.fd_di == NULL 4133 if (arg != NULL && (fudi.fd_di == NULL
4134 || (fudi.fd_di->di_tv.v_type != VAR_FUNC 4134 || (fudi.fd_di->di_tv.v_type != VAR_FUNC
4135 && fudi.fd_di->di_tv.v_type != VAR_PARTIAL))) 4135 && fudi.fd_di->di_tv.v_type != VAR_PARTIAL)))
4136 { 4136 {
4137 char_u *name_base = arg;
4138 int i;
4139
4137 if (*arg == K_SPECIAL) 4140 if (*arg == K_SPECIAL)
4138 j = 3; 4141 {
4139 else 4142 name_base = vim_strchr(arg, '_');
4140 j = 0; 4143 if (name_base == NULL)
4141 while (arg[j] != NUL && (j == 0 ? eval_isnamec1(arg[j]) 4144 name_base = arg + 3;
4142 : eval_isnamec(arg[j]))) 4145 else
4143 ++j; 4146 ++name_base;
4144 if (arg[j] != NUL) 4147 }
4148 for (i = 0; name_base[i] != NUL && (i == 0
4149 ? eval_isnamec1(name_base[i])
4150 : eval_isnamec(name_base[i])); ++i)
4151 ;
4152 if (name_base[i] != NUL)
4145 emsg_funcname((char *)e_invarg2, arg); 4153 emsg_funcname((char *)e_invarg2, arg);
4154
4155 // In Vim9 script a function cannot have the same name as a
4156 // variable.
4157 if (vim9script && *arg == K_SPECIAL
4158 && eval_variable(name_base, STRLEN(name_base), NULL, NULL,
4159 EVAL_VAR_NOAUTOLOAD + EVAL_VAR_IMPORT
4160 + EVAL_VAR_NO_FUNC) == OK)
4161 {
4162 semsg(_(e_redefining_script_item_str), name_base);
4163 goto ret_free;
4164 }
4146 } 4165 }
4147 // Disallow using the g: dict. 4166 // Disallow using the g: dict.
4148 if (fudi.fd_dict != NULL && fudi.fd_dict->dv_scope == VAR_DEF_SCOPE) 4167 if (fudi.fd_dict != NULL && fudi.fd_dict->dv_scope == VAR_DEF_SCOPE)
4168 {
4149 emsg(_("E862: Cannot use g: here")); 4169 emsg(_("E862: Cannot use g: here"));
4170 goto ret_free;
4171 }
4150 } 4172 }
4151 4173
4152 // This may get more lines and make the pointers into the first line 4174 // This may get more lines and make the pointers into the first line
4153 // invalid. 4175 // invalid.
4154 ++p; 4176 ++p;