comparison src/userfunc.c @ 21598:7b5b9558500a v8.2.1349

patch 8.2.1349: Vim9: can define a function with the name of an import Commit: https://github.com/vim/vim/commit/eef2102e20d24f5fbd1c9f53c7a35df61585c5ab Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 1 22:16:43 2020 +0200 patch 8.2.1349: Vim9: can define a function with the name of an import Problem: Vim9: can define a function with the name of an import. Solution: Disallow using an existing name. (closes https://github.com/vim/vim/issues/6585)
author Bram Moolenaar <Bram@vim.org>
date Sat, 01 Aug 2020 22:30:04 +0200
parents 5470c36ed7e6
children a640bc762196
comparison
equal deleted inserted replaced
21597:b26b1529cb9b 21598:7b5b9558500a
2650 linenr_T sourcing_lnum_top; 2650 linenr_T sourcing_lnum_top;
2651 int is_heredoc = FALSE; 2651 int is_heredoc = FALSE;
2652 char_u *skip_until = NULL; 2652 char_u *skip_until = NULL;
2653 char_u *heredoc_trimmed = NULL; 2653 char_u *heredoc_trimmed = NULL;
2654 int vim9script = in_vim9script(); 2654 int vim9script = in_vim9script();
2655 imported_T *import = NULL;
2655 2656
2656 /* 2657 /*
2657 * ":function" without argument: list functions. 2658 * ":function" without argument: list functions.
2658 */ 2659 */
2659 if (ends_excmd2(eap->cmd, eap->arg)) 2660 if (ends_excmd2(eap->cmd, eap->arg))
3233 name); 3234 name);
3234 goto erret; 3235 goto erret;
3235 } 3236 }
3236 3237
3237 fp = find_func_even_dead(name, is_global, NULL); 3238 fp = find_func_even_dead(name, is_global, NULL);
3238 if (fp != NULL) 3239 if (vim9script)
3239 { 3240 {
3240 int dead = fp->uf_flags & FC_DEAD; 3241 char_u *uname = untrans_function_name(name);
3242
3243 import = find_imported(uname == NULL ? name : uname, 0, NULL);
3244 }
3245
3246 if (fp != NULL || import != NULL)
3247 {
3248 int dead = fp != NULL && (fp->uf_flags & FC_DEAD);
3241 3249
3242 // Function can be replaced with "function!" and when sourcing the 3250 // Function can be replaced with "function!" and when sourcing the
3243 // same script again, but only once. 3251 // same script again, but only once.
3244 if (!dead && !eap->forceit 3252 // A name that is used by an import can not be overruled.
3253 if (import != NULL
3254 || (!dead && !eap->forceit
3245 && (fp->uf_script_ctx.sc_sid != current_sctx.sc_sid 3255 && (fp->uf_script_ctx.sc_sid != current_sctx.sc_sid
3246 || fp->uf_script_ctx.sc_seq == current_sctx.sc_seq)) 3256 || fp->uf_script_ctx.sc_seq == current_sctx.sc_seq)))
3247 { 3257 {
3248 emsg_funcname(e_funcexts, name); 3258 if (vim9script)
3259 emsg_funcname(e_already_defined, name);
3260 else
3261 emsg_funcname(e_funcexts, name);
3249 goto erret; 3262 goto erret;
3250 } 3263 }
3251 if (fp->uf_calls > 0) 3264 if (fp->uf_calls > 0)
3252 { 3265 {
3253 emsg_funcname( 3266 emsg_funcname(