]> granicus.if.org Git - vim/commitdiff
patch 8.2.4871: Vim9: in :def function no error for misplaced range v8.2.4871
authorBram Moolenaar <Bram@vim.org>
Thu, 5 May 2022 14:20:03 +0000 (15:20 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 5 May 2022 14:20:03 +0000 (15:20 +0100)
Problem:    Vim9: in :def function no error for using a range with a command
            that does not accept one.
Solution:   Check for the command to accept a range. (closes #10330)

src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index dd33a923ac5d3cb7e20d8e3353f7c753ec14d5e9..4fa6904509713bae5d88a01bdb44dd18a7d8465c 100644 (file)
@@ -67,6 +67,29 @@ def Test_range_only()
   endif
 enddef
 
+def Test_invalid_range()
+  var lines =<< trim END
+      :123 eval 1 + 2
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E481:', 1)
+
+  lines =<< trim END
+      :123 if true
+      endif
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E481:', 1)
+
+  lines =<< trim END
+      :123 echo 'yes'
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E481:', 1)
+
+  lines =<< trim END
+      :123 cd there
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E481:', 1)
+enddef
+
 let g:alist = [7]
 let g:astring = 'text'
 let g:anumber = 123
index 3f7825eee2ec5e7c95ca4f852f3695b28574c892..f0269e44dd9b68a4da916dbd56fe3af49c87b648 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4871,
 /**/
     4870,
 /**/
index 8b22a8db2ff27a2ea23f2e29b8775080416b2135..b0cf6a787f46bc90cb5e68e7d653b738444887ef 100644 (file)
@@ -3080,6 +3080,11 @@ compile_def_function(
                ea.forceit = TRUE;
                p = skipwhite(p + 1);
            }
+           if ((ea.argt & EX_RANGE) == 0 && ea.addr_count > 0)
+           {
+               emsg(_(e_no_range_allowed));
+               goto erret;
+           }
        }
 
        switch (ea.cmdidx)