Mercurial > vim
comparison src/vim9script.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 | 7e76d5fba19f |
children | ad37a198a708 |
comparison
equal
deleted
inserted
replaced
19622:684f747f0568 | 19623:2fee087c94cb |
---|---|
141 { | 141 { |
142 if (current_sctx.sc_version != SCRIPT_VERSION_VIM9) | 142 if (current_sctx.sc_version != SCRIPT_VERSION_VIM9) |
143 emsg(_(e_needs_vim9)); | 143 emsg(_(e_needs_vim9)); |
144 else | 144 else |
145 { | 145 { |
146 char_u *cmd_end = handle_import(eap->arg, NULL, current_sctx.sc_sid); | 146 char_u *cmd_end = handle_import(eap->arg, NULL, |
147 current_sctx.sc_sid, NULL); | |
147 | 148 |
148 if (cmd_end != NULL) | 149 if (cmd_end != NULL) |
149 eap->nextcmd = check_nextcmd(cmd_end); | 150 eap->nextcmd = check_nextcmd(cmd_end); |
150 } | 151 } |
151 } | 152 } |
236 * Handle an ":import" command and add the resulting imported_T to "gap", when | 237 * Handle an ":import" command and add the resulting imported_T to "gap", when |
237 * not NULL, or script "import_sid" sn_imports. | 238 * not NULL, or script "import_sid" sn_imports. |
238 * Returns a pointer to after the command or NULL in case of failure | 239 * Returns a pointer to after the command or NULL in case of failure |
239 */ | 240 */ |
240 char_u * | 241 char_u * |
241 handle_import(char_u *arg_start, garray_T *gap, int import_sid) | 242 handle_import(char_u *arg_start, garray_T *gap, int import_sid, void *cctx) |
242 { | 243 { |
243 char_u *arg = arg_start; | 244 char_u *arg = arg_start; |
244 char_u *cmd_end; | 245 char_u *cmd_end; |
245 char_u *as_ptr = NULL; | 246 char_u *as_ptr = NULL; |
246 char_u *from_ptr; | 247 char_u *from_ptr; |
276 if (eval_isnamec1(*arg)) | 277 if (eval_isnamec1(*arg)) |
277 while (eval_isnamec(*arg)) | 278 while (eval_isnamec(*arg)) |
278 ++arg; | 279 ++arg; |
279 as_len = (int)(arg - as_ptr); | 280 as_len = (int)(arg - as_ptr); |
280 arg = skipwhite(arg); | 281 arg = skipwhite(arg); |
282 if (check_defined(as_ptr, as_len, cctx) == FAIL) | |
283 return NULL; | |
281 } | 284 } |
282 else if (*arg_start == '*') | 285 else if (*arg_start == '*') |
283 { | 286 { |
284 emsg(_("E1045: Missing \"as\" after *")); | 287 emsg(_("E1045: Missing \"as\" after *")); |
285 return NULL; | 288 return NULL; |
385 type_T *type; | 388 type_T *type; |
386 | 389 |
387 idx = find_exported(sid, &arg, &name_len, &ufunc, &type); | 390 idx = find_exported(sid, &arg, &name_len, &ufunc, &type); |
388 | 391 |
389 if (idx < 0 && ufunc == NULL) | 392 if (idx < 0 && ufunc == NULL) |
393 return NULL; | |
394 | |
395 if (check_defined(name, name_len, cctx) == FAIL) | |
390 return NULL; | 396 return NULL; |
391 | 397 |
392 imported = new_imported(gap != NULL ? gap | 398 imported = new_imported(gap != NULL ? gap |
393 : &SCRIPT_ITEM(import_sid)->sn_imports); | 399 : &SCRIPT_ITEM(import_sid)->sn_imports); |
394 if (imported == NULL) | 400 if (imported == NULL) |