Patch 8.2.1426
Problem: Vim9: cannot call autoload function in :def function.
Solution: Load the autoload script. (closes #6690)
Files: src/vim9execute.c, src/vim9compile.c, src/scriptfile.c,
src/testdir/test_vim9_expr.vim
*** ../vim-8.2.1425/src/vim9execute.c 2020-08-01 15:38:33.941599081 +0200
--- src/vim9execute.c 2020-08-12 15:20:52.722743636 +0200
***************
*** 546,551 ****
--- 546,560 ----
}
/*
+ * Return TRUE if an error was given or CTRL-C was pressed.
+ */
+ static int
+ vim9_aborting(int prev_called_emsg)
+ {
+ return called_emsg > prev_called_emsg || got_int || did_throw;
+ }
+
+ /*
* Execute a function by "name".
* This can be a builtin function or a user function.
* "iptr" can be used to replace the instruction with a more efficient one.
***************
*** 568,573 ****
--- 577,594 ----
}
ufunc = find_func(name, FALSE, NULL);
+
+ if (ufunc == NULL)
+ {
+ int called_emsg_before = called_emsg;
+
+ if (script_autoload(name, TRUE))
+ // loaded a package, search for the function again
+ ufunc = find_func(name, FALSE, NULL);
+ if (vim9_aborting(called_emsg_before))
+ return FAIL; // bail out if loading the script caused an error
+ }
+
if (ufunc != NULL)
return call_ufunc(ufunc, argcount, ectx, iptr);
*** ../vim-8.2.1425/src/vim9compile.c 2020-08-12 14:21:06.263590410 +0200
--- src/vim9compile.c 2020-08-12 15:03:26.894566551 +0200
***************
*** 2214,2219 ****
--- 2214,2220 ----
int error = FCERR_NONE;
ufunc_T *ufunc;
int res = FAIL;
+ int is_autoload;
// we can evaluate "has('name')" at compile time
if (varlen == 3 && STRNCMP(*arg, "has", 3) == 0)
***************
*** 2258,2264 ****
if (compile_arguments(arg, cctx, &argcount) == FAIL)
goto theend;
! if (ASCII_ISLOWER(*name) && name[1] != ':')
{
int idx;
--- 2259,2266 ----
if (compile_arguments(arg, cctx, &argcount) == FAIL)
goto theend;
! is_autoload = vim_strchr(name, '#') != NULL;
! if (ASCII_ISLOWER(*name) && name[1] != ':' && !is_autoload)
{
int idx;
***************
*** 2281,2288 ****
// If the name is a variable, load it and use PCALL.
// Not for g:Func(), we don't know if it is a variable or not.
p = namebuf;
! if (STRNCMP(namebuf, "g:", 2) != 0
&& compile_load(&p, namebuf + varlen, cctx, FALSE) == OK)
{
garray_T *stack = &cctx->ctx_type_stack;
--- 2283,2291 ----
// If the name is a variable, load it and use PCALL.
// Not for g:Func(), we don't know if it is a variable or not.
+ // Not for eome#Func(), it will be loaded later.
p = namebuf;
! if (STRNCMP(namebuf, "g:", 2) != 0 && !is_autoload
&& compile_load(&p, namebuf + varlen, cctx, FALSE) == OK)
{
garray_T *stack = &cctx->ctx_type_stack;
***************
*** 2295,2301 ****
// A global function may be defined only later. Need to figure out at
// runtime. Also handles a FuncRef at runtime.
! if (STRNCMP(namebuf, "g:", 2) == 0)
res = generate_UCALL(cctx, name, argcount);
else
semsg(_(e_unknownfunc), namebuf);
--- 2298,2304 ----
// A global function may be defined only later. Need to figure out at
// runtime. Also handles a FuncRef at runtime.
! if (STRNCMP(namebuf, "g:", 2) == 0 || is_autoload)
res = generate_UCALL(cctx, name, argcount);
else
semsg(_(e_unknownfunc), namebuf);
*** ../vim-8.2.1425/src/scriptfile.c 2020-08-08 21:33:17.788742735 +0200
--- src/scriptfile.c 2020-08-12 14:49:43.297328664 +0200
***************
*** 1991,1997 ****
if (scriptname == NULL)
return NULL;
STRCPY(scriptname, "autoload/");
! STRCAT(scriptname, name);
for (p = scriptname + 9; (p = vim_strchr(p, AUTOLOAD_CHAR)) != NULL;
q = p, ++p)
*p = '/';
--- 1991,1997 ----
if (scriptname == NULL)
return NULL;
STRCPY(scriptname, "autoload/");
! STRCAT(scriptname, name[0] == 'g' && name[1] == ':' ? name + 2: name);
for (p = scriptname + 9; (p = vim_strchr(p, AUTOLOAD_CHAR)) != NULL;
q = p, ++p)
*p = '/';
*** ../vim-8.2.1425/src/testdir/test_vim9_expr.vim 2020-08-10
23:09:33.761270906 +0200
--- src/testdir/test_vim9_expr.vim 2020-08-12 14:57:12.027879135 +0200
***************
*** 1752,1757 ****
--- 1752,1772 ----
"vim9script",
"let x = substitute ('x', 'x', 'x', 'x')"
], 'E121:')
+
+ let auto_lines =<< trim END
+ def g:some#func(): string
+ return 'found'
+ enddef
+ END
+ mkdir('Xruntime/autoload', 'p')
+ writefile(auto_lines, 'Xruntime/autoload/some.vim')
+ let save_rtp = &rtp
+ &rtp = getcwd() .. '/Xruntime,' .. &rtp
+ assert_equal('found', g:some#func())
+ assert_equal('found', some#func())
+
+ &rtp = save_rtp
+ delete('Xruntime', 'rf')
enddef
*** ../vim-8.2.1425/src/version.c 2020-08-12 14:21:06.263590410 +0200
--- src/version.c 2020-08-12 14:51:04.333082234 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1426,
/**/
--
hundred-and-one symptoms of being an internet addict:
177. You log off of your system because it's time to go to work.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202008121322.07CDML6j052125%40masaka.moolenaar.net.