]> granicus.if.org Git - vim/commitdiff
patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines v8.2.1392
authorBram Moolenaar <Bram@vim.org>
Sat, 8 Aug 2020 12:26:31 +0000 (14:26 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 8 Aug 2020 12:26:31 +0000 (14:26 +0200)
Problem:    Vim9: error line number incorrect after skipping over comment
            lines.
Solution:   Insert empty lines for skipped lines.

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

index 649ef4806921b96e39de1c6f3a6e84fbe1065035..3cc1e112b6ab9f36fc30db5f0c869b6c82c3c29e 100644 (file)
@@ -984,6 +984,47 @@ func DelMe()
   echo 'DelMe'
 endfunc
 
+def Test_error_reporting()
+  # comment lines at the start of the function
+  let lines =<< trim END
+    " comment
+    def Func()
+      # comment
+      # comment
+      invalid
+    enddef
+    defcompile
+  END
+  call writefile(lines, 'Xdef')
+  try
+    source Xdef
+  catch /E476:/
+    assert_match('Invalid command: invalid', v:exception)
+    assert_match(', line 3$', v:throwpoint)
+  endtry
+
+  # comment lines after the start of the function
+  lines =<< trim END
+    " comment
+    def Func()
+      let x = 1234
+      # comment
+      # comment
+      invalid
+    enddef
+    defcompile
+  END
+  call writefile(lines, 'Xdef')
+  try
+    source Xdef
+  catch /E476:/
+    assert_match('Invalid command: invalid', v:exception)
+    assert_match(', line 4$', v:throwpoint)
+  endtry
+
+  call delete('Xdef')
+enddef
+
 def Test_deleted_function()
   CheckDefExecFailure([
       'let RefMe: func = function("g:DelMe")',
index 684a805d8abaf0197451719e285f6bbc3b64de4f..10d1c3b77b9c3156bd2fbe61b6a844679e44d778 100644 (file)
@@ -2961,6 +2961,18 @@ def_function(exarg_T *eap, char_u *name_arg)
     // Save the starting line number.
     sourcing_lnum_top = SOURCING_LNUM;
 
+    // Detect having skipped over comment lines to find the return
+    // type.  Add NULL lines to keep the line count correct.
+    sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie);
+    if (SOURCING_LNUM < sourcing_lnum_off)
+    {
+       sourcing_lnum_off -= SOURCING_LNUM;
+       if (ga_grow(&newlines, sourcing_lnum_off) == FAIL)
+           goto erret;
+       while (sourcing_lnum_off-- > 0)
+           ((char_u **)(newlines.ga_data))[newlines.ga_len++] = NULL;
+    }
+
     indent = 2;
     nesting = 0;
     nesting_def[nesting] = (eap->cmdidx == CMD_def);
index 978920e81ce4029a5b5774d3ede81c9a22b2cd38..0f6dfc1d9a887de59c1c8ff5736fbe7c2fa58414 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1392,
 /**/
     1391,
 /**/