Patch 8.2.4131
Problem: Vim9: calling function in autoload import does not work in a :def
function.
Solution: When a variable is not found and a PCALL follows use a funcref.
(closes #9550)
Files: src/vim9execute.c, src/testdir/test_vim9_import.vim
*** ../vim-8.2.4130/src/vim9execute.c 2022-01-13 21:15:17.237958552 +0000
--- src/vim9execute.c 2022-01-18 12:57:54.886847099 +0000
***************
*** 2200,2209 ****
case ISN_LOADW:
case ISN_LOADT:
{
! dictitem_T *di = NULL;
! hashtab_T *ht = NULL;
! char namespace;
switch (iptr->isn_type)
{
case ISN_LOADG:
--- 2200,2211 ----
case ISN_LOADW:
case ISN_LOADT:
{
! dictitem_T *di = NULL;
! hashtab_T *ht = NULL;
! char namespace;
+ if (GA_GROW_FAILS(&ectx->ec_stack, 1))
+ goto theend;
switch (iptr->isn_type)
{
case ISN_LOADG:
***************
*** 2227,2240 ****
}
di = find_var_in_ht(ht, 0, iptr->isn_arg.string, TRUE);
! if (di == NULL && ht == get_globvar_ht())
{
! // may need to load autoload script
if (script_autoload(iptr->isn_arg.string, FALSE))
di = find_var_in_ht(ht, 0,
iptr->isn_arg.string, TRUE);
if (did_emsg)
goto on_error;
}
if (di == NULL)
--- 2229,2266 ----
}
di = find_var_in_ht(ht, 0, iptr->isn_arg.string, TRUE);
! if (di == NULL && ht == get_globvar_ht()
! && vim_strchr(iptr->isn_arg.string,
! AUTOLOAD_CHAR) != NULL)
{
! // Global variable has an autoload name, may still need
! // to load the script.
if (script_autoload(iptr->isn_arg.string, FALSE))
di = find_var_in_ht(ht, 0,
iptr->isn_arg.string, TRUE);
if (did_emsg)
goto on_error;
+ if (di == NULL)
+ {
+ isn_T *next = &ectx->ec_instr[ectx->ec_iidx];
+
+ // When compiling "script.Func()" when "script" is
+ // an autoload import then this results in
+ // "LOADG script#Func" because we don't know if it
+ // is a funcref variable or a function name. In
+ // that case a PCALL follows, push the function
+ // name instead.
+ if (next->isn_type == ISN_PCALL)
+ {
+ tv = STACK_TV_BOT(0);
+ tv->v_type = VAR_FUNC;
+ tv->v_lock = 0;
+ tv->vval.v_string =
+ vim_strsave(iptr->isn_arg.string);
+ ++ectx->ec_stack.ga_len;
+ break;
+ }
+ }
}
if (di == NULL)
***************
*** 2246,2253 ****
}
else
{
- if (GA_GROW_FAILS(&ectx->ec_stack, 1))
- goto theend;
copy_tv(&di->di_tv, STACK_TV_BOT(0));
++ectx->ec_stack.ga_len;
}
--- 2272,2277 ----
*** ../vim-8.2.4130/src/testdir/test_vim9_import.vim 2022-01-17
20:09:02.860881495 +0000
--- src/testdir/test_vim9_import.vim 2022-01-18 12:52:12.635941381 +0000
***************
*** 1264,1269 ****
--- 1264,1273 ----
var lines =<< trim END
vim9script autoload
+ export def RetArg(arg: string): string
+ return arg
+ enddef
+
export def Getother()
g:result = 'other'
enddef
***************
*** 1273,1278 ****
--- 1277,1289 ----
lines =<< trim END
vim9script
import autoload 'another.vim'
+
+ # compile this before 'another.vim' is loaded
+ def CallAnother()
+ assert_equal('foo', 'foo'->another.RetArg())
+ enddef
+ CallAnother()
+
call another.Getother()
assert_equal('other', g:result)
END
*** ../vim-8.2.4130/src/version.c 2022-01-18 11:34:52.889893556 +0000
--- src/version.c 2022-01-18 12:38:26.182071139 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4131,
/**/
--
ARTHUR: Be quiet!
DENNIS: Well you can't expect to wield supreme executive power just 'cause
some watery tart threw a sword at you!
ARTHUR: Shut up!
DENNIS: I mean, if I went around sayin' I was an empereror just because some
moistened bint had lobbed a scimitar at me they'd put me away!
The Quest for the Holy Grail (Monty Python)
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ 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/20220118125855.0F77C1C044E%40moolenaar.net.