summaryrefslogtreecommitdiff
path: root/src/vim9compile.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-03-09 19:25:27 +0100
committerBram Moolenaar <Bram@vim.org>2020-03-09 19:25:27 +0100
commit5269bd2a724fdb8c16c9635ef744a670f1bc8bd5 (patch)
tree18c5fb9d7cd245085c16c86b6f2b05ed7a1530ac /src/vim9compile.c
parent3a2505cc183b3c5f4852ae8a945172582fbc650f (diff)
downloadvim-git-5269bd2a724fdb8c16c9635ef744a670f1bc8bd5.tar.gz
patch 8.2.0368: Vim9: import that redefines local variable does not failv8.2.0368
Problem: Vim9: import that redefines local variable does not fail. Solution: Check for already defined symbols.
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r--src/vim9compile.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 6618b6ace..38b904d29 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -203,6 +203,25 @@ lookup_script(char_u *name, size_t len)
return di == NULL ? FAIL: OK;
}
+/*
+ * Check if "p[len]" is already defined, either in script "import_sid" or in
+ * compilation context "cctx".
+ * Return FAIL and give an error if it defined.
+ */
+ int
+check_defined(char_u *p, int len, cctx_T *cctx)
+{
+ if (lookup_script(p, len) == OK
+ || (cctx != NULL
+ && (lookup_local(p, len, cctx) >= 0
+ || find_imported(p, len, cctx) != NULL)))
+ {
+ semsg("E1073: imported name already defined: %s", p);
+ return FAIL;
+ }
+ return OK;
+}
+
static type_T *
get_list_type(type_T *member_type, garray_T *type_list)
{
@@ -3812,7 +3831,7 @@ theend:
static char_u *
compile_import(char_u *arg, cctx_T *cctx)
{
- return handle_import(arg, &cctx->ctx_imports, 0);
+ return handle_import(arg, &cctx->ctx_imports, 0, cctx);
}
/*