patch 8.2.4872: Vim9: no error for using an expression only v8.2.4872
authorBram Moolenaar <Bram@vim.org>
Thu, 5 May 2022 15:08:55 +0000 (16:08 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 5 May 2022 15:08:55 +0000 (16:08 +0100)
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)

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

index 9a2792a2ac01f2f044f61bdf85a931b23aec6822..e9dbd107c85cdac5226b5f9f7384efde301b1a51 100644 (file)
@@ -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);
index 4cd78f6d11b3c74fd180e8146fe5ab237f67b1c6..50719e1b54925572218e3e4b949322e42b9ec89c 100644 (file)
@@ -650,6 +650,20 @@ def Test_use_register()
   END
   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'
       @/
index f0269e44dd9b68a4da916dbd56fe3af49c87b648..5ad75510f8788c3323a3e19979b56b3418720a9d 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4872,
 /**/
     4871,
 /**/