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.
diff --git a/src/vim9script.c b/src/vim9script.c
index 6cea96b..ce5cfec 100644
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -143,7 +143,8 @@
emsg(_(e_needs_vim9));
else
{
- char_u *cmd_end = handle_import(eap->arg, NULL, current_sctx.sc_sid);
+ char_u *cmd_end = handle_import(eap->arg, NULL,
+ current_sctx.sc_sid, NULL);
if (cmd_end != NULL)
eap->nextcmd = check_nextcmd(cmd_end);
@@ -238,7 +239,7 @@
* Returns a pointer to after the command or NULL in case of failure
*/
char_u *
-handle_import(char_u *arg_start, garray_T *gap, int import_sid)
+handle_import(char_u *arg_start, garray_T *gap, int import_sid, void *cctx)
{
char_u *arg = arg_start;
char_u *cmd_end;
@@ -278,6 +279,8 @@
++arg;
as_len = (int)(arg - as_ptr);
arg = skipwhite(arg);
+ if (check_defined(as_ptr, as_len, cctx) == FAIL)
+ return NULL;
}
else if (*arg_start == '*')
{
@@ -389,6 +392,9 @@
if (idx < 0 && ufunc == NULL)
return NULL;
+ if (check_defined(name, name_len, cctx) == FAIL)
+ return NULL;
+
imported = new_imported(gap != NULL ? gap
: &SCRIPT_ITEM(import_sid)->sn_imports);
if (imported == NULL)