Skip to content

Commit 5d72ce6

Browse files
committed
patch 8.2.1500: Vim9: error when using address without a command
Problem: Vim9: error when using address without a command. Solution: Execute the range itself. (closes #6747)
1 parent ec65d77 commit 5d72ce6

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ def Test_syntax()
1010
let other: list<string> = ['asdf']
1111
enddef
1212

13+
def Test_range_only()
14+
new
15+
setline(1, ['blah', 'Blah'])
16+
:/Blah/
17+
assert_equal(2, getcurpos()[1])
18+
enddef
19+
1320
let s:appendToMe = 'xxx'
1421
let s:addToMe = 111
1522
let g:existing = 'yes'

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1500,
757759
/**/
758760
1499,
759761
/**/

src/vim9compile.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6661,10 +6661,22 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
66616661
if (*cmd != '\'' || starts_with_colon)
66626662
{
66636663
ea.cmd = skip_range(ea.cmd, NULL);
6664-
if (ea.cmd > cmd && !starts_with_colon)
6664+
if (ea.cmd > cmd)
66656665
{
6666-
emsg(_(e_colon_required_before_a_range));
6667-
goto erret;
6666+
if (!starts_with_colon)
6667+
{
6668+
emsg(_(e_colon_required_before_a_range));
6669+
goto erret;
6670+
}
6671+
if (ends_excmd2(line, ea.cmd))
6672+
{
6673+
// A range without a command: jump to the line.
6674+
// TODO: compile to a more efficient command, possibly
6675+
// calling parse_cmd_address().
6676+
ea.cmdidx = CMD_SIZE;
6677+
line = compile_exec(line, &ea, &cctx);
6678+
goto nextline;
6679+
}
66686680
}
66696681
}
66706682
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)
68456857
line = compile_exec(line, &ea, &cctx);
68466858
break;
68476859
}
6860+
nextline:
68486861
if (line == NULL)
68496862
goto erret;
68506863
line = skipwhite(line);

0 commit comments

Comments
 (0)