changeset 28895:228154db3ce6 v8.2.4970

patch 8.2.4970: "eval 123" gives an error, "eval 'abc'" does not Commit: https://github.com/vim/vim/commit/0d03263fd731986c0eee1a08e0f1b19f1bc3a7ad Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 17 12:45:15 2022 +0100 patch 8.2.4970: "eval 123" gives an error, "eval 'abc'" does not Problem: "eval 123" gives an error, "eval 'abc'" does not. Solution: Also give an error when evaluating only a string. (closes https://github.com/vim/vim/issues/10434)
author Bram Moolenaar <Bram@vim.org>
date Tue, 17 May 2022 14:00:05 +0200
parents 05217054f93c
children 915bc19857dd
files src/ex_eval.c src/testdir/test_vim9_cmd.vim src/version.c
diffstat 3 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/ex_eval.c
+++ b/src/ex_eval.c
@@ -888,8 +888,8 @@ report_discard_pending(int pending, void
 }
 
 /*
- * 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 == '&')
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -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()
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4970,
+/**/
     4969,
 /**/
     4968,