From: Bram Moolenaar Date: Mon, 12 Apr 2021 20:02:36 +0000 (+0200) Subject: patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name X-Git-Tag: v8.2.2758 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f48b2fa33cda94e963f6fa8b78f344385c9ebea6;p=vim patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name Problem: Vim9: wrong line number for autoload function with wrong name. Solution: Set and restore SOURCING_LNUM. (closes #8100) --- diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim index a97146d45..a941a6102 100644 --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -74,6 +74,30 @@ def TestCompilingErrorInTry() delete('Xdir', 'rf') enddef +def Test_autoload_name_mismatch() + var dir = 'Xdir/autoload' + mkdir(dir, 'p') + + var lines =<< trim END + vim9script + def scriptX#Function() + # comment + g:runtime = 'yes' + enddef + END + writefile(lines, dir .. '/script.vim') + + var save_rtp = &rtp + exe 'set rtp=' .. getcwd() .. '/Xdir' + lines =<< trim END + call script#Function() + END + CheckScriptFailure(lines, 'E746:', 2) + + &rtp = save_rtp + delete(dir, 'rf') +enddef + def CallRecursive(n: number): number return CallRecursive(n + 1) enddef diff --git a/src/userfunc.c b/src/userfunc.c index 54335d41f..772d45d12 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -4058,7 +4058,11 @@ define_function(exarg_T *eap, char_u *name_arg) } if (j == FAIL) { + linenr_T save_lnum = SOURCING_LNUM; + + SOURCING_LNUM = sourcing_lnum_top; semsg(_("E746: Function name does not match script file name: %s"), name); + SOURCING_LNUM = save_lnum; goto erret; } } diff --git a/src/version.c b/src/version.c index 3728f320e..4e6121053 100644 --- a/src/version.c +++ b/src/version.c @@ -750,6 +750,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2758, /**/ 2757, /**/