]> granicus.if.org Git - vim/commitdiff
patch 8.2.4970: "eval 123" gives an error, "eval 'abc'" does not v8.2.4970
authorBram Moolenaar <Bram@vim.org>
Tue, 17 May 2022 11:45:15 +0000 (12:45 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 17 May 2022 11:45:15 +0000 (12:45 +0100)
Problem:    "eval 123" gives an error, "eval 'abc'" does not.
Solution:   Also give an error when evaluating only a string. (closes #10434)

src/ex_eval.c
src/testdir/test_vim9_cmd.vim
src/version.c

index f3e2ca28cfe3702101c7e285b36d97c2c08ee0d0..61d288157da8ec2d8e827aa73796205eff4c3bfa 100644 (file)
@@ -888,8 +888,8 @@ report_discard_pending(int pending, void *value)
 }
 
 /*
- * Return TRUE if "arg" is only a variable, register, environment variable or
- * option name.
+ * Return TRUE if "arg" is only a variable, register, environment variable,
+ * option name or string.
  */
     int
 cmd_is_name_only(char_u *arg)
@@ -904,6 +904,17 @@ cmd_is_name_only(char_u *arg)
        if (*p != NUL)
            ++p;
     }
+    else if (*p == '\'' || *p == '"')
+    {
+       int         r;
+
+       if (*p == '"')
+           r = eval_string(&p, NULL, FALSE, FALSE);
+       else
+           r = eval_lit_string(&p, NULL, FALSE, FALSE);
+       if (r == FAIL)
+           return FALSE;
+    }
     else
     {
        if (*p == '&')
index 50719e1b54925572218e3e4b949322e42b9ec89c..77e1d8a0696483f691bf18d769626da88497b82f 100644 (file)
@@ -697,6 +697,16 @@ def Test_use_register()
   END
   v9.CheckDefAndScriptFailure(lines, 'E1207:', 2)
   $SomeEnv = ''
+
+  lines =<< trim END
+      eval 'value'
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E1207:', 1)
+
+  lines =<< trim END
+      eval "value"
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E1207:', 1)
 enddef
 
 def Test_environment_use_linebreak()
index 485e25780b3a5d640cc8100df78ba1d818825961..7bdf346336482b19ad22695d943acfcb43db8fd7 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4970,
 /**/
     4969,
 /**/