diff src/userfunc.c @ 21685:26a4b53c4587 v8.2.1392

patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines Commit: https://github.com/vim/vim/commit/bf8feb5aeb71c8f56897845c4134793201aa459a Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 8 14:26:31 2020 +0200 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines Problem: Vim9: error line number incorrect after skipping over comment lines. Solution: Insert empty lines for skipped lines.
author Bram Moolenaar <Bram@vim.org>
date Sat, 08 Aug 2020 14:30:04 +0200
parents a640bc762196
children 1b96535705a0
line wrap: on
line diff
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -2961,6 +2961,18 @@ def_function(exarg_T *eap, char_u *name_
     // 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);