]> granicus.if.org Git - vim/commitdiff
patch 8.2.1499: Vim9: error when using "$" with col() v8.2.1499
authorBram Moolenaar <Bram@vim.org>
Thu, 20 Aug 2020 20:29:12 +0000 (22:29 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 20 Aug 2020 20:29:12 +0000 (22:29 +0200)
Problem:    Vim9: error when using "$" with col().
Solution:   Reorder getting the column value. (closes #6744)

src/eval.c
src/testdir/test_vim9_func.vim
src/version.c

index 741599bbf85c4725c3203bc987175484a18db4bb..cc044a4bd740968bd398d797f80fe4e4a7327c98 100644 (file)
@@ -4841,19 +4841,23 @@ var2fpos(
        pos.lnum = list_find_nr(l, 0L, &error);
        if (error || pos.lnum <= 0 || pos.lnum > curbuf->b_ml.ml_line_count)
            return NULL;        // invalid line number
-
-       // Get the column number
-       pos.col = list_find_nr(l, 1L, &error);
-       if (error)
-           return NULL;
        len = (long)STRLEN(ml_get(pos.lnum));
 
+       // Get the column number
        // We accept "$" for the column number: last column.
        li = list_find(l, 1L);
        if (li != NULL && li->li_tv.v_type == VAR_STRING
                && li->li_tv.vval.v_string != NULL
                && STRCMP(li->li_tv.vval.v_string, "$") == 0)
+       {
            pos.col = len + 1;
+       }
+       else
+       {
+           pos.col = list_find_nr(l, 1L, &error);
+           if (error)
+               return NULL;
+       }
 
        // Accept a position up to the NUL after the line.
        if (pos.col == 0 || (int)pos.col > len + 1)
index 1f0fd1c8a3d72e3820a229ab530fed7c0e67e8f6..466110881577578ce207560996686ea5a8fdcb6d 100644 (file)
@@ -1320,6 +1320,12 @@ def Test_bufnr()
   assert_equal(buf, bufnr('%'))
 enddef
 
+def Test_col()
+  new
+  setline(1, 'asdf')
+  assert_equal(5, col([1, '$']))
+enddef
+
 def Test_getreg_return_type()
   let s1: string = getreg('"')
   let s2: string = getreg('"', 1)
index 51306efa1634ed0f45ef90a8cb6f8c9f208342a4..d1c75a385f0eb0891b1f3778c7f850aa1ebae5de 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1499,
 /**/
     1498,
 /**/