Skip to content

Commit 17f700a

Browse files
committed
patch 8.2.2164: Vim9: autoload function doesn't work in uppercased script
Problem: Vim9: autoload function doesn't work in script that starts with an upper case letter. Solution: Check for the autoload character. (closes #7502)
1 parent 13656f0 commit 17f700a

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/testdir/test_vim9_script.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,6 +2799,16 @@ def Test_vim9_autoload()
27992799
g:some#other = 'other'
28002800
assert_equal('other', g:some#other)
28012801

2802+
# upper case script name works
2803+
lines =<< trim END
2804+
vim9script
2805+
def Other#getOther(): string
2806+
return 'other'
2807+
enddef
2808+
END
2809+
writefile(lines, 'Xdir/autoload/Other.vim')
2810+
assert_equal('other', g:Other#getOther())
2811+
28022812
delete('Xdir', 'rf')
28032813
&rtp = save_rtp
28042814
enddef

src/userfunc.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2654,8 +2654,18 @@ trans_function_name(
26542654
goto theend;
26552655
}
26562656

2657-
// In Vim9 script a user function is script-local by default.
2657+
// In Vim9 script a user function is script-local by default, unless it
2658+
// starts with a lower case character: dict.func().
26582659
vim9script = ASCII_ISUPPER(*start) && in_vim9script();
2660+
if (vim9script)
2661+
{
2662+
char_u *p;
2663+
2664+
// SomeScript#func() is a global function.
2665+
for (p = start; *p != NUL && *p != '('; ++p)
2666+
if (*p == AUTOLOAD_CHAR)
2667+
vim9script = FALSE;
2668+
}
26592669

26602670
/*
26612671
* Copy the function name to allocated memory.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2164,
753755
/**/
754756
2163,
755757
/**/

0 commit comments

Comments
 (0)