summaryrefslogtreecommitdiff
path: root/src/userfunc.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-08-01 22:16:43 +0200
committerBram Moolenaar <Bram@vim.org>2020-08-01 22:16:43 +0200
commiteef2102e20d24f5fbd1c9f53c7a35df61585c5ab (patch)
tree1bfa42d3637ea2b19021b1a7f6e859791f343ad4 /src/userfunc.c
parente4218b9416bdcd78b9779a06258198573a0c369e (diff)
downloadvim-git-eef2102e20d24f5fbd1c9f53c7a35df61585c5ab.tar.gz
patch 8.2.1349: Vim9: can define a function with the name of an importv8.2.1349
Problem: Vim9: can define a function with the name of an import. Solution: Disallow using an existing name. (closes #6585)
Diffstat (limited to 'src/userfunc.c')
-rw-r--r--src/userfunc.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/userfunc.c b/src/userfunc.c
index 520c114ef..43aa146a9 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -2652,6 +2652,7 @@ def_function(exarg_T *eap, char_u *name_arg)
char_u *skip_until = NULL;
char_u *heredoc_trimmed = NULL;
int vim9script = in_vim9script();
+ imported_T *import = NULL;
/*
* ":function" without argument: list functions.
@@ -3235,17 +3236,29 @@ def_function(exarg_T *eap, char_u *name_arg)
}
fp = find_func_even_dead(name, is_global, NULL);
- if (fp != NULL)
+ if (vim9script)
+ {
+ char_u *uname = untrans_function_name(name);
+
+ import = find_imported(uname == NULL ? name : uname, 0, NULL);
+ }
+
+ if (fp != NULL || import != NULL)
{
- int dead = fp->uf_flags & FC_DEAD;
+ int dead = fp != NULL && (fp->uf_flags & FC_DEAD);
// Function can be replaced with "function!" and when sourcing the
// same script again, but only once.
- if (!dead && !eap->forceit
+ // A name that is used by an import can not be overruled.
+ if (import != NULL
+ || (!dead && !eap->forceit
&& (fp->uf_script_ctx.sc_sid != current_sctx.sc_sid
- || fp->uf_script_ctx.sc_seq == current_sctx.sc_seq))
+ || fp->uf_script_ctx.sc_seq == current_sctx.sc_seq)))
{
- emsg_funcname(e_funcexts, name);
+ if (vim9script)
+ emsg_funcname(e_already_defined, name);
+ else
+ emsg_funcname(e_funcexts, name);
goto erret;
}
if (fp->uf_calls > 0)