# HG changeset patch # User Bram Moolenaar # Date 1596889804 -7200 # Node ID 26a4b53c45871438af7b202dbb0d368200beddce # Parent 70ae376858130879030e8e01c637a0a7e0d3def8 patch 8.2.1392: Vim9: line number incorrect after skipping over comment lines Commit: https://github.com/vim/vim/commit/bf8feb5aeb71c8f56897845c4134793201aa459a Author: Bram Moolenaar 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. diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -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")', diff --git a/src/userfunc.c b/src/userfunc.c --- 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); diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1392, +/**/ 1391, /**/ 1390,