Patch 8.2.2975

1 view
Skip to first unread message

Bram Moolenaar

unread,
Jun 11, 2021, 4:06:29 PM6/11/21
to vim...@googlegroups.com

Patch 8.2.2975
Problem: Vim9: can only use an autoload function name as a string.
Solution: Load the autoload script when encountered. (closes #8124)
Files: src/vim9compile.c, src/evalvars.c, src/scriptfile.c,
src/testdir/test_vim9_func.vim


*** ../vim-8.2.2974/src/vim9compile.c 2021-06-08 22:01:48.750571749 +0200
--- src/vim9compile.c 2021-06-11 20:36:30.456546418 +0200
***************
*** 3084,3090 ****
if (name == NULL)
return FAIL;

! if (arg_exists(*arg, len, &idx, &type, &gen_load_outer, cctx) == OK)
{
if (gen_load_outer == 0)
gen_load = TRUE;
--- 3084,3096 ----
if (name == NULL)
return FAIL;

! 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;
*** ../vim-8.2.2974/src/evalvars.c 2021-06-10 18:43:21.743644898 +0200
--- src/evalvars.c 2021-06-11 20:43:41.043429626 +0200
***************
*** 2921,2928 ****
if (ht != NULL)
return ht; // local variable

! // in Vim9 script items at the script level are script-local
! if (in_vim9script())
{
ht = get_script_local_ht();
if (ht != NULL)
--- 2921,2929 ----
if (ht != NULL)
return ht; // local variable

! // 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)
*** ../vim-8.2.2974/src/scriptfile.c 2021-06-03 21:56:06.664423437 +0200
--- src/scriptfile.c 2021-06-11 21:47:40.413254243 +0200
***************
*** 1128,1133 ****
--- 1128,1134 ----
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,1147 ****
--- 1143,1149 ----
smsg(_("Cannot source a directory: \"%s\""), fname);
goto theend;
}
+ estack_compiling = FALSE;

#ifdef FEAT_EVAL
// See if we loaded this script before.
***************
*** 1508,1513 ****
--- 1510,1516 ----

theend:
vim_free(fname_exp);
+ estack_compiling = save_estack_compiling;
return retval;
}

*** ../vim-8.2.2974/src/testdir/test_vim9_func.vim 2021-06-09 19:29:59.888951195 +0200
--- src/testdir/test_vim9_func.vim 2021-06-11 22:01:23.455084345 +0200
***************
*** 114,119 ****
--- 114,147 ----
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
*** ../vim-8.2.2974/src/version.c 2021-06-11 19:07:36.734247944 +0200
--- src/version.c 2021-06-11 22:02:22.298929834 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2975,
/**/

--
OLD WOMAN: King of the WHO?
ARTHUR: The Britons.
OLD WOMAN: Who are the Britons?
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages