]> granicus.if.org Git - vim/commitdiff
patch 8.2.1500: Vim9: error when using address without a command v8.2.1500
authorBram Moolenaar <Bram@vim.org>
Thu, 20 Aug 2020 21:04:06 +0000 (23:04 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 20 Aug 2020 21:04:06 +0000 (23:04 +0200)
Problem:    Vim9: error when using address without a command.
Solution:   Execute the range itself. (closes #6747)

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

index d442dc2548127542b24c75ab073bb250649cee11..e8f07069c25a8e43e33ae41c7ac1ceb24e65e483 100644 (file)
@@ -10,6 +10,13 @@ def Test_syntax()
   let other: list<string> = ['asdf']
 enddef
 
+def Test_range_only()
+  new
+  setline(1, ['blah', 'Blah'])
+  :/Blah/
+  assert_equal(2, getcurpos()[1])
+enddef
+
 let s:appendToMe = 'xxx'
 let s:addToMe = 111
 let g:existing = 'yes'
index d1c75a385f0eb0891b1f3778c7f850aa1ebae5de..bd836e0700b3d1c3e51d2d3108b536d4afb28212 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1500,
 /**/
     1499,
 /**/
index 025e8cbc6e563ff2237b48962bda31e626c707fb..f1936452a94d39940d1e85278b90d94c20bd978b 100644 (file)
@@ -6661,10 +6661,22 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
        if (*cmd != '\'' || starts_with_colon)
        {
            ea.cmd = skip_range(ea.cmd, NULL);
-           if (ea.cmd > cmd && !starts_with_colon)
+           if (ea.cmd > cmd)
            {
-               emsg(_(e_colon_required_before_a_range));
-               goto erret;
+               if (!starts_with_colon)
+               {
+                   emsg(_(e_colon_required_before_a_range));
+                   goto erret;
+               }
+               if (ends_excmd2(line, ea.cmd))
+               {
+                   // A range without a command: jump to the line.
+                   // TODO: compile to a more efficient command, possibly
+                   // calling parse_cmd_address().
+                   ea.cmdidx = CMD_SIZE;
+                   line = compile_exec(line, &ea, &cctx);
+                   goto nextline;
+               }
            }
        }
        p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
@@ -6845,6 +6857,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
                    line = compile_exec(line, &ea, &cctx);
                    break;
        }
+nextline:
        if (line == NULL)
            goto erret;
        line = skipwhite(line);