changeset 28696:a090c60278f5 v8.2.4872

patch 8.2.4872: Vim9: no error for using an expression only Commit: https://github.com/vim/vim/commit/ea72038d60401d351faaf1b4a52f4537e719df6f Author: Bram Moolenaar <Bram@vim.org> Date: Thu May 5 16:08:55 2022 +0100 patch 8.2.4872: Vim9: no error for using an expression only Problem: Vim9: no error for using an expression only at the script level when followed by an empty line. Solution: Do not check the line number but whether something follows. (closes #10357)
author Bram Moolenaar <Bram@vim.org>
date Thu, 05 May 2022 17:15:05 +0200
parents 7ad8f631bae5
children 4b66e6223f65
files src/ex_eval.c src/testdir/test_vim9_cmd.vim src/version.c
diffstat 3 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ex_eval.c
+++ b/src/ex_eval.c
@@ -940,8 +940,14 @@ ex_eval(exarg_T *eap)
     if (eval0(eap->arg, &tv, eap, &evalarg) == OK)
     {
 	clear_tv(&tv);
-	if (in_vim9script() && name_only && lnum == SOURCING_LNUM)
+	if (in_vim9script() && name_only
+		&& (evalarg.eval_tofree == NULL
+		    || ends_excmd2(evalarg.eval_tofree,
+					      skipwhite(evalarg.eval_tofree))))
+	{
+	    SOURCING_LNUM = lnum;
 	    semsg(_(e_expression_without_effect_str), eap->arg);
+	}
     }
 
     clear_evalarg(&evalarg, eap);
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -651,6 +651,20 @@ def Test_use_register()
   v9.CheckDefAndScriptFailure(lines, 'E1207:', 2)
 
   lines =<< trim END
+      @a = 'echo "text"'
+      @a
+
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E1207:', 2)
+
+  lines =<< trim END
+      @a = 'echo "text"'
+      @a
+          # comment
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E1207:', 2)
+
+  lines =<< trim END
       @/ = 'pattern'
       @/
   END
--- 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 */
 /**/
+    4872,
+/**/
     4871,
 /**/
     4870,