To: vim_dev@googlegroups.com Subject: Patch 8.2.2525 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2525 Problem: Vim9: only local variables checked for a name. Solution: Also check arguments and script variables. (closes #7838) Files: src/vim9compile.c, src/ex_docmd.c, src/proto/ex_docmd.pro, src/testdir/test_vim9_cmd.vim *** ../vim-8.2.2524/src/vim9compile.c 2021-02-14 16:34:54.877413319 +0100 --- src/vim9compile.c 2021-02-17 14:42:50.733093938 +0100 *************** *** 373,378 **** --- 373,391 ---- } /* + * Return TRUE if "name" is a local variable, argument, script variable or + * imported. + */ + static int + variable_exists(char_u *name, size_t len, cctx_T *cctx) + { + return lookup_local(name, len, NULL, cctx) == OK + || arg_exists(name, len, NULL, NULL, NULL, cctx) == OK + || script_var_exists(name, len, FALSE, cctx) == OK + || find_imported(name, len, cctx) != NULL; + } + + /* * Check if "p[len]" is already defined, either in script "import_sid" or in * compilation context "cctx". "cctx" is NULL at the script level. * Does not check the global namespace. *************** *** 6444,6453 **** || *eap->cmd == '$' || *eap->cmd == '@' || ((len) > 2 && eap->cmd[1] == ':') ! || lookup_local(eap->cmd, len, NULL, cctx) == OK ! || arg_exists(eap->cmd, len, NULL, NULL, NULL, cctx) == OK ! || script_var_exists(eap->cmd, len, FALSE, cctx) == OK ! || find_imported(eap->cmd, len, cctx) != NULL) { *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx); if (*line == NULL || *line == eap->cmd) --- 6457,6463 ---- || *eap->cmd == '$' || *eap->cmd == '@' || ((len) > 2 && eap->cmd[1] == ':') ! || variable_exists(eap->cmd, len, cctx)) { *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx); if (*line == NULL || *line == eap->cmd) *************** *** 8332,8338 **** } } p = find_ex_command(&ea, NULL, starts_with_colon ? NULL ! : (int (*)(char_u *, size_t, void *, cctx_T *))lookup_local, &cctx); if (p == NULL) --- 8342,8348 ---- } } p = find_ex_command(&ea, NULL, starts_with_colon ? NULL ! : (int (*)(char_u *, size_t, cctx_T *))variable_exists, &cctx); if (p == NULL) *** ../vim-8.2.2524/src/ex_docmd.c 2021-02-15 21:30:26.750092486 +0100 --- src/ex_docmd.c 2021-02-17 14:41:17.997352973 +0100 *************** *** 3307,3313 **** find_ex_command( exarg_T *eap, int *full UNUSED, ! int (*lookup)(char_u *, size_t, void *, cctx_T *) UNUSED, cctx_T *cctx UNUSED) { int len; --- 3307,3313 ---- find_ex_command( exarg_T *eap, int *full UNUSED, ! int (*lookup)(char_u *, size_t, cctx_T *) UNUSED, cctx_T *cctx UNUSED) { int len; *************** *** 3416,3422 **** // Recognize an assignment if we recognize the variable name: // "g:var = expr" ! // "var = expr" where "var" is a local var name. if (*eap->cmd == '@') p = eap->cmd + 2; oplen = assignment_len(skipwhite(p), &heredoc); --- 3416,3422 ---- // Recognize an assignment if we recognize the variable name: // "g:var = expr" ! // "var = expr" where "var" is a variable name. if (*eap->cmd == '@') p = eap->cmd + 2; oplen = assignment_len(skipwhite(p), &heredoc); *************** *** 3426,3432 **** || *eap->cmd == '&' || *eap->cmd == '$' || *eap->cmd == '@' ! || lookup(eap->cmd, p - eap->cmd, NULL, cctx) == OK) { eap->cmdidx = CMD_var; return eap->cmd; --- 3426,3432 ---- || *eap->cmd == '&' || *eap->cmd == '$' || *eap->cmd == '@' ! || lookup(eap->cmd, p - eap->cmd, cctx) == OK) { eap->cmdidx = CMD_var; return eap->cmd; *************** *** 3445,3451 **** // If it is an ID it might be a variable with an operator on the next // line, if the variable exists it can't be an Ex command. if (p > eap->cmd && ends_excmd(*skipwhite(p)) ! && (lookup(eap->cmd, p - eap->cmd, NULL, cctx) == OK || (ASCII_ISALPHA(eap->cmd[0]) && eap->cmd[1] == ':'))) { eap->cmdidx = CMD_eval; --- 3445,3451 ---- // If it is an ID it might be a variable with an operator on the next // line, if the variable exists it can't be an Ex command. if (p > eap->cmd && ends_excmd(*skipwhite(p)) ! && (lookup(eap->cmd, p - eap->cmd, cctx) == OK || (ASCII_ISALPHA(eap->cmd[0]) && eap->cmd[1] == ':'))) { eap->cmdidx = CMD_eval; *** ../vim-8.2.2524/src/proto/ex_docmd.pro 2021-01-16 20:20:59.646487092 +0100 --- src/proto/ex_docmd.pro 2021-02-17 14:41:26.953327939 +0100 *************** *** 13,21 **** int parse_cmd_address(exarg_T *eap, char **errormsg, int silent); int checkforcmd(char_u **pp, char *cmd, int len); char_u *skip_option_env_lead(char_u *start); ! char_u *find_ex_command(exarg_T *eap, int *full, int (*lookup)(char_u *, size_t, void *, cctx_T *), cctx_T *cctx); int modifier_len(char_u *cmd); int cmd_exists(char_u *name); cmdidx_T excmd_get_cmdidx(char_u *cmd, int len); long excmd_get_argt(cmdidx_T idx); char_u *skip_range(char_u *cmd, int skip_star, int *ctx); --- 13,22 ---- int parse_cmd_address(exarg_T *eap, char **errormsg, int silent); int checkforcmd(char_u **pp, char *cmd, int len); char_u *skip_option_env_lead(char_u *start); ! char_u *find_ex_command(exarg_T *eap, int *full, int (*lookup)(char_u *, size_t, cctx_T *), cctx_T *cctx); int modifier_len(char_u *cmd); int cmd_exists(char_u *name); + void f_fullcommand(typval_T *argvars, typval_T *rettv); cmdidx_T excmd_get_cmdidx(char_u *cmd, int len); long excmd_get_argt(cmdidx_T idx); char_u *skip_range(char_u *cmd, int skip_star, int *ctx); *** ../vim-8.2.2524/src/testdir/test_vim9_cmd.vim 2021-02-14 12:57:32.552655477 +0100 --- src/testdir/test_vim9_cmd.vim 2021-02-17 14:46:23.052464488 +0100 *************** *** 323,328 **** --- 323,333 ---- CheckScriptSuccess(lines) enddef + def MethodAfterLinebreak(arg: string) + arg + ->setline(1) + enddef + def Test_method_call_linebreak() var lines =<< trim END vim9script *************** *** 361,366 **** --- 366,376 ---- g:shortlist = [1, 2] CheckDefAndScriptSuccess(lines) unlet g:shortlist + + new + MethodAfterLinebreak('foobar') + assert_equal('foobar', getline(1)) + bwipe! enddef def Test_method_call_whitespace() *** ../vim-8.2.2524/src/version.c 2021-02-17 13:14:03.688013283 +0100 --- src/version.c 2021-02-17 14:46:46.700387717 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2525, /**/ -- There are three kinds of people: Those who can count & those who can't. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///