Mercurial > vim
diff src/vim9compile.c @ 19623:2fee087c94cb v8.2.0368
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Commit: https://github.com/vim/vim/commit/5269bd2a724fdb8c16c9635ef744a670f1bc8bd5
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Mar 9 19:25:27 2020 +0100
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Problem: Vim9: import that redefines local variable does not fail.
Solution: Check for already defined symbols.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 09 Mar 2020 19:30:04 +0100 |
parents | 1098989a90ee |
children | ad37a198a708 |
line wrap: on
line diff
--- 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); } /*