]> granicus.if.org Git - vim/commitdiff
patch 8.2.2525: Vim9: only local variables checked for a name v8.2.2525
authorBram Moolenaar <Bram@vim.org>
Wed, 17 Feb 2021 13:52:14 +0000 (14:52 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 17 Feb 2021 13:52:14 +0000 (14:52 +0100)
Problem:    Vim9: only local variables checked for a name.
Solution:   Also check arguments and script variables. (closes #7838)

src/ex_docmd.c
src/proto/ex_docmd.pro
src/testdir/test_vim9_cmd.vim
src/version.c
src/vim9compile.c

index f4bdf7b152b2c5c8b9bf0139301b811a6c9df13b..77a7a71a7b125259adf06803cb43e17d50c554a5 100644 (file)
@@ -3307,7 +3307,7 @@ skip_option_env_lead(char_u *start)
 find_ex_command(
        exarg_T *eap,
        int     *full UNUSED,
-       int     (*lookup)(char_u *, size_t, void *, cctx_T *) UNUSED,
+       int     (*lookup)(char_u *, size_t, cctx_T *) UNUSED,
        cctx_T  *cctx UNUSED)
 {
     int                len;
@@ -3416,7 +3416,7 @@ find_ex_command(
 
            // Recognize an assignment if we recognize the variable name:
            // "g:var = expr"
-           // "var = expr"  where "var" is a local var name.
+           // "var = expr"  where "var" is a variable name.
            if (*eap->cmd == '@')
                p = eap->cmd + 2;
            oplen = assignment_len(skipwhite(p), &heredoc);
@@ -3426,7 +3426,7 @@ find_ex_command(
                        || *eap->cmd == '&'
                        || *eap->cmd == '$'
                        || *eap->cmd == '@'
-                       || lookup(eap->cmd, p - eap->cmd, NULL, cctx) == OK)
+                       || lookup(eap->cmd, p - eap->cmd, cctx) == OK)
                {
                    eap->cmdidx = CMD_var;
                    return eap->cmd;
@@ -3445,7 +3445,7 @@ find_ex_command(
        // 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
+               && (lookup(eap->cmd, p - eap->cmd, cctx) == OK
                    || (ASCII_ISALPHA(eap->cmd[0]) && eap->cmd[1] == ':')))
        {
            eap->cmdidx = CMD_eval;
index 94770f2e3c0b70b602311a979b27516b63f52367..dcd9f3940cc122aab7a56d99a01f11a62fede2e2 100644 (file)
@@ -13,9 +13,10 @@ void undo_cmdmod(cmdmod_T *cmod);
 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);
+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);
index 42c51b46cdec358f1ae96332b4b17547a30da6e3..9a0460bdeb4615540837098d6ab64563002fe50a 100644 (file)
@@ -323,6 +323,11 @@ def Test_for_linebreak()
   CheckScriptSuccess(lines)
 enddef
 
+def MethodAfterLinebreak(arg: string)
+  arg
+    ->setline(1)
+enddef
+
 def Test_method_call_linebreak()
   var lines =<< trim END
       vim9script
@@ -361,6 +366,11 @@ def Test_method_call_linebreak()
   g:shortlist = [1, 2]
   CheckDefAndScriptSuccess(lines)
   unlet g:shortlist
+
+  new
+  MethodAfterLinebreak('foobar')
+  assert_equal('foobar', getline(1))
+  bwipe!
 enddef
 
 def Test_method_call_whitespace()
index 26f80cc992d7b0c545601060bc9a003ecf41bc2c..ad117896c49aa2611f4e74d6f74195d7d34d86f2 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2525,
 /**/
     2524,
 /**/
index 6d0a748824cee6a2841c0ce051feebe3ddf61bab..84c9108cacca6bc8e8676d0ac308fe2ad54a980c 100644 (file)
@@ -372,6 +372,19 @@ script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx)
     return FAIL;
 }
 
+/*
+ * 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.
@@ -6444,10 +6457,7 @@ may_compile_assignment(exarg_T *eap, char_u **line, cctx_T *cctx)
                    || *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)
+                   || variable_exists(eap->cmd, len, cctx))
            {
                *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx);
                if (*line == NULL || *line == eap->cmd)
@@ -8332,7 +8342,7 @@ compile_def_function(
            }
        }
        p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
-                  : (int (*)(char_u *, size_t, void *, cctx_T *))lookup_local,
+                  : (int (*)(char_u *, size_t, cctx_T *))variable_exists,
                                                                        &cctx);
 
        if (p == NULL)