summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-04-12 22:02:36 +0200
committerBram Moolenaar <Bram@vim.org>2021-04-12 22:02:36 +0200
commitf48b2fa33cda94e963f6fa8b78f344385c9ebea6 (patch)
treee65e350985a0baf3870a1a9567d02bd6d8e90734 /src
parent68452177ca4cda4a9d5f93892e437447cf9404c8 (diff)
downloadvim-git-f48b2fa33cda94e963f6fa8b78f344385c9ebea6.tar.gz
patch 8.2.2758: Vim9: wrong line number for autoload function with wrong namev8.2.2758
Problem: Vim9: wrong line number for autoload function with wrong name. Solution: Set and restore SOURCING_LNUM. (closes #8100)
Diffstat (limited to 'src')
-rw-r--r--src/testdir/test_vim9_func.vim24
-rw-r--r--src/userfunc.c4
-rw-r--r--src/version.c2
3 files changed, 30 insertions, 0 deletions
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
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2758,
+/**/
2757,
/**/
2756,