comparison src/vim9compile.c @ 23966:09bde146adcb v8.2.2525

patch 8.2.2525: Vim9: only local variables checked for a name Commit: https://github.com/vim/vim/commit/e0890d678d4d31ca1810c90f3afe2ba89dfedcfa Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 17 14:52:14 2021 +0100 patch 8.2.2525: Vim9: only local variables checked for a name Problem: Vim9: only local variables checked for a name. Solution: Also check arguments and script variables. (closes https://github.com/vim/vim/issues/7838)
author Bram Moolenaar <Bram@vim.org>
date Wed, 17 Feb 2021 15:00:04 +0100
parents 9854b4c6d5e6
children 54b2aa1f0d42
comparison
equal deleted inserted replaced
23965:ece767530ffc 23966:09bde146adcb
368 if (di != NULL) 368 if (di != NULL)
369 return OK; 369 return OK;
370 } 370 }
371 371
372 return FAIL; 372 return FAIL;
373 }
374
375 /*
376 * Return TRUE if "name" is a local variable, argument, script variable or
377 * imported.
378 */
379 static int
380 variable_exists(char_u *name, size_t len, cctx_T *cctx)
381 {
382 return lookup_local(name, len, NULL, cctx) == OK
383 || arg_exists(name, len, NULL, NULL, NULL, cctx) == OK
384 || script_var_exists(name, len, FALSE, cctx) == OK
385 || find_imported(name, len, cctx) != NULL;
373 } 386 }
374 387
375 /* 388 /*
376 * Check if "p[len]" is already defined, either in script "import_sid" or in 389 * Check if "p[len]" is already defined, either in script "import_sid" or in
377 * compilation context "cctx". "cctx" is NULL at the script level. 390 * compilation context "cctx". "cctx" is NULL at the script level.
6442 // "@r = expr" 6455 // "@r = expr"
6443 if (*eap->cmd == '&' 6456 if (*eap->cmd == '&'
6444 || *eap->cmd == '$' 6457 || *eap->cmd == '$'
6445 || *eap->cmd == '@' 6458 || *eap->cmd == '@'
6446 || ((len) > 2 && eap->cmd[1] == ':') 6459 || ((len) > 2 && eap->cmd[1] == ':')
6447 || lookup_local(eap->cmd, len, NULL, cctx) == OK 6460 || variable_exists(eap->cmd, len, cctx))
6448 || arg_exists(eap->cmd, len, NULL, NULL, NULL, cctx) == OK
6449 || script_var_exists(eap->cmd, len, FALSE, cctx) == OK
6450 || find_imported(eap->cmd, len, cctx) != NULL)
6451 { 6461 {
6452 *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx); 6462 *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx);
6453 if (*line == NULL || *line == eap->cmd) 6463 if (*line == NULL || *line == eap->cmd)
6454 return FAIL; 6464 return FAIL;
6455 return OK; 6465 return OK;
8330 goto nextline; 8340 goto nextline;
8331 } 8341 }
8332 } 8342 }
8333 } 8343 }
8334 p = find_ex_command(&ea, NULL, starts_with_colon ? NULL 8344 p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
8335 : (int (*)(char_u *, size_t, void *, cctx_T *))lookup_local, 8345 : (int (*)(char_u *, size_t, cctx_T *))variable_exists,
8336 &cctx); 8346 &cctx);
8337 8347
8338 if (p == NULL) 8348 if (p == NULL)
8339 { 8349 {
8340 if (cctx.ctx_skip != SKIP_YES) 8350 if (cctx.ctx_skip != SKIP_YES)