]> granicus.if.org Git - vim/commitdiff
patch 8.2.3376: Vim9: no warning that "@r" does not do anything v8.2.3376
authorBram Moolenaar <Bram@vim.org>
Wed, 25 Aug 2021 20:37:36 +0000 (22:37 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 25 Aug 2021 20:37:36 +0000 (22:37 +0200)
Problem:    Vim9: no warning that "@r" does not do anything.
Solution:   Give a "no effect" error. (closes #8779)

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

index 207defa7f3dc1e3bd420473b7f4658087e83e3cd..259cf670cc6e0fd518065742f6dd4cca6126f0e6 100644 (file)
@@ -887,6 +887,26 @@ report_discard_pending(int pending, void *value)
     }
 }
 
+    int
+cmd_is_name_only(char_u *arg)
+{
+    char_u  *p = arg;
+    char_u  *alias;
+    int            name_only = FALSE;
+
+    if (*p == '&')
+    {
+       ++p;
+       if (STRNCMP("l:", p, 2) == 0 || STRNCMP("g:", p, 2) == 0)
+           p += 2;
+    }
+    else if (*p == '@')
+       ++p;
+    get_name_len(&p, &alias, FALSE, FALSE);
+    name_only = ends_excmd2(arg, skipwhite(p));
+    vim_free(alias);
+    return name_only;
+}
 
 /*
  * ":eval".
@@ -897,18 +917,10 @@ ex_eval(exarg_T *eap)
     typval_T   tv;
     evalarg_T  evalarg;
     int                name_only = FALSE;
-    char_u     *p;
     long       lnum = SOURCING_LNUM;
 
     if (in_vim9script())
-    {
-       char_u  *alias;
-
-       p = eap->arg;
-       get_name_len(&p, &alias, FALSE, FALSE);
-       name_only = ends_excmd2(eap->arg, skipwhite(p));
-       vim_free(alias);
-    }
+       name_only = cmd_is_name_only(eap->arg);
 
     fill_evalarg_from_eap(&evalarg, eap, eap->skip);
 
index f5037c932506b38102e5f2bacda5f0dbcbd2e61e..a3be429b1945bff2bc8e0209b78b29d524aae52c 100644 (file)
@@ -12,6 +12,7 @@ int throw_exception(void *value, except_type_T type, char_u *cmdname);
 void discard_current_exception(void);
 void catch_exception(except_T *excp);
 void report_make_pending(int pending, void *value);
+int cmd_is_name_only(char_u *arg);
 void ex_eval(exarg_T *eap);
 void ex_if(exarg_T *eap);
 void ex_endif(exarg_T *eap);
index 128575b955b86ff0678c8344ab1d122f2c519d54..93b1295d4ca9a92ef8cb590f2ca400e88fd7af19 100644 (file)
@@ -537,7 +537,7 @@ def Test_option_use_linebreak()
   CheckDefAndScriptSuccess(lines)
 enddef
 
-def Test_register_use_linebreak()
+def Test_use_register()
   var lines =<< trim END
       new
       @a = 'one'
@@ -551,6 +551,12 @@ def Test_register_use_linebreak()
       bwipe!
   END
   CheckDefAndScriptSuccess(lines)
+
+  lines =<< trim END
+      @a = 'echo "text"'
+      @a
+  END
+  CheckDefAndScriptFailure(lines, 'E1207:')
 enddef
 
 def Test_environment_use_linebreak()
index 5211f8faeee3b680744a013ab447a39249f8b548..22dc4400456805e5e568fc572d4e54b20a3a35f6 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3376,
 /**/
     3375,
 /**/
index 97bd292bba96bb80ca6281093cc63721de8e0233..a4d8423fca0173bb737ca7d04daf0b0e68dad372 100644 (file)
@@ -8828,17 +8828,13 @@ compile_eval(char_u *arg, cctx_T *cctx)
 {
     char_u     *p = arg;
     int                name_only;
-    char_u     *alias;
     long       lnum = SOURCING_LNUM;
 
     // find_ex_command() will consider a variable name an expression, assuming
     // that something follows on the next line.  Check that something actually
     // follows, otherwise it's probably a misplaced command.
-    get_name_len(&p, &alias, FALSE, FALSE);
-    name_only = ends_excmd2(arg, skipwhite(p));
-    vim_free(alias);
+    name_only = cmd_is_name_only(arg);
 
-    p = arg;
     if (compile_expr0(&p, cctx) == FAIL)
        return NULL;