Skip to content

Commit ec65d77

Browse files
committed
patch 8.2.1499: Vim9: error when using "$" with col()
Problem: Vim9: error when using "$" with col(). Solution: Reorder getting the column value. (closes #6744)
1 parent 733d259 commit ec65d77

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/eval.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4841,19 +4841,23 @@ var2fpos(
48414841
pos.lnum = list_find_nr(l, 0L, &error);
48424842
if (error || pos.lnum <= 0 || pos.lnum > curbuf->b_ml.ml_line_count)
48434843
return NULL; // invalid line number
4844-
4845-
// Get the column number
4846-
pos.col = list_find_nr(l, 1L, &error);
4847-
if (error)
4848-
return NULL;
48494844
len = (long)STRLEN(ml_get(pos.lnum));
48504845

4846+
// Get the column number
48514847
// We accept "$" for the column number: last column.
48524848
li = list_find(l, 1L);
48534849
if (li != NULL && li->li_tv.v_type == VAR_STRING
48544850
&& li->li_tv.vval.v_string != NULL
48554851
&& STRCMP(li->li_tv.vval.v_string, "$") == 0)
4852+
{
48564853
pos.col = len + 1;
4854+
}
4855+
else
4856+
{
4857+
pos.col = list_find_nr(l, 1L, &error);
4858+
if (error)
4859+
return NULL;
4860+
}
48574861

48584862
// Accept a position up to the NUL after the line.
48594863
if (pos.col == 0 || (int)pos.col > len + 1)

src/testdir/test_vim9_func.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,12 @@ def Test_bufnr()
13201320
assert_equal(buf, bufnr('%'))
13211321
enddef
13221322

1323+
def Test_col()
1324+
new
1325+
setline(1, 'asdf')
1326+
assert_equal(5, col([1, '$']))
1327+
enddef
1328+
13231329
def Test_getreg_return_type()
13241330
let s1: string = getreg('"')
13251331
let s2: string = getreg('"', 1)

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+
1499,
757759
/**/
758760
1498,
759761
/**/

0 commit comments

Comments
 (0)