diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-06-11 22:05:47 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-06-11 22:05:47 +0200 |
commit | f0a4069e3df904ac6bd57718ec06e56c5d7363e4 (patch) | |
tree | 7f58de7700fa10cb7e4216d9f847b65479ae9833 | |
parent | 4f135275984722c1b1e9ace72eeeb7ce7e4ec983 (diff) | |
download | vim-git-f0a4069e3df904ac6bd57718ec06e56c5d7363e4.tar.gz |
patch 8.2.2975: Vim9: can only use an autoload function name as a stringv8.2.2975
Problem: Vim9: can only use an autoload function name as a string.
Solution: Load the autoload script when encountered. (closes #8124)
-rw-r--r-- | src/evalvars.c | 5 | ||||
-rw-r--r-- | src/scriptfile.c | 3 | ||||
-rw-r--r-- | src/testdir/test_vim9_func.vim | 28 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 8 |
5 files changed, 43 insertions, 3 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index 7581a1417..cd1f1702f 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -2921,8 +2921,9 @@ find_var_ht(char_u *name, char_u **varname) if (ht != NULL) return ht; // local variable - // in Vim9 script items at the script level are script-local - if (in_vim9script()) + // In Vim9 script items at the script level are script-local, except + // for autoload names. + if (in_vim9script() && vim_strchr(name, AUTOLOAD_CHAR) == NULL) { ht = get_script_local_ht(); if (ht != NULL) diff --git a/src/scriptfile.c b/src/scriptfile.c index bbc415664..eefe39a13 100644 --- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -1128,6 +1128,7 @@ do_source( proftime_T wait_start; #endif int trigger_source_post = FALSE; + int save_estack_compiling = estack_compiling; ESTACK_CHECK_DECLARATION p = expand_env_save(fname); @@ -1142,6 +1143,7 @@ do_source( smsg(_("Cannot source a directory: \"%s\""), fname); goto theend; } + estack_compiling = FALSE; #ifdef FEAT_EVAL // See if we loaded this script before. @@ -1508,6 +1510,7 @@ almosttheend: theend: vim_free(fname_exp); + estack_compiling = save_estack_compiling; return retval; } diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim index 8d891d2b1..96e144f5d 100644 --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -114,6 +114,34 @@ def Test_autoload_name_mismatch() delete(dir, 'rf') enddef +def Test_autoload_names() + var dir = 'Xdir/autoload' + mkdir(dir, 'p') + + var lines =<< trim END + func foobar#function() + return 'yes' + endfunc + let foobar#var = 'no' + END + writefile(lines, dir .. '/foobar.vim') + + var save_rtp = &rtp + exe 'set rtp=' .. getcwd() .. '/Xdir' + + lines =<< trim END + assert_equal('yes', foobar#function()) + var Function = foobar#function + assert_equal('yes', Function()) + + assert_equal('no', foobar#var) + END + CheckDefAndScriptSuccess(lines) + + &rtp = save_rtp + delete(dir, 'rf') +enddef + def CallRecursive(n: number): number return CallRecursive(n + 1) enddef diff --git a/src/version.c b/src/version.c index 99a635b46..0a113f432 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 */ /**/ + 2975, +/**/ 2974, /**/ 2973, diff --git a/src/vim9compile.c b/src/vim9compile.c index 6fcad3db4..44c082d41 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -3084,7 +3084,13 @@ compile_load( if (name == NULL) return FAIL; - if (arg_exists(*arg, len, &idx, &type, &gen_load_outer, cctx) == OK) + if (vim_strchr(name, AUTOLOAD_CHAR) != NULL) + { + script_autoload(name, FALSE); + res = generate_LOAD(cctx, ISN_LOADAUTO, 0, name, &t_any); + } + else if (arg_exists(*arg, len, &idx, &type, &gen_load_outer, cctx) + == OK) { if (gen_load_outer == 0) gen_load = TRUE; |