Patch 8.2.1541
Problem: Vim9: cannot find function reference for s:Func.
Solution: Recognize <SNR> prefix. (closes #6805)
Files: src/userfunc.c, src/vim9execute.c,
src/testdir/test_vim9_script.vim
*** ../vim-8.2.1540/src/userfunc.c 2020-08-28 17:19:03.831887039 +0200
--- src/userfunc.c 2020-08-29 17:09:20.348785921 +0200
***************
*** 808,818 ****
if (!is_global)
{
- int vim9script = in_vim9script();
char_u *after_script = NULL;
long sid = 0;
! if (vim9script)
{
// Find script-local function before global one.
func = find_func_with_sid(name, current_sctx.sc_sid);
--- 808,819 ----
if (!is_global)
{
char_u *after_script = NULL;
long sid = 0;
+ int find_script_local = in_vim9script()
+ && eval_isnamec1(*name) && name[1] != ':';
! if (find_script_local)
{
// Find script-local function before global one.
func = find_func_with_sid(name, current_sctx.sc_sid);
***************
*** 833,839 ****
else
after_script = NULL;
}
! if (vim9script || after_script != NULL)
{
// Find imported function before global one.
if (after_script != NULL && sid != current_sctx.sc_sid)
--- 834,840 ----
else
after_script = NULL;
}
! if (find_script_local || after_script != NULL)
{
// Find imported function before global one.
if (after_script != NULL && sid != current_sctx.sc_sid)
*** ../vim-8.2.1540/src/vim9execute.c 2020-08-28 17:19:03.831887039 +0200
--- src/vim9execute.c 2020-08-29 17:42:22.386822906 +0200
***************
*** 614,619 ****
--- 614,620 ----
int argcount = argcount_arg;
char_u *name = NULL;
int called_emsg_before = called_emsg;
+ int res;
if (tv->v_type == VAR_PARTIAL)
{
***************
*** 650,656 ****
}
else if (tv->v_type == VAR_FUNC)
name = tv->vval.v_string;
! if (name == NULL || call_by_name(name, argcount, ectx, NULL) == FAIL)
{
if (called_emsg == called_emsg_before)
semsg(_(e_unknownfunc),
--- 651,673 ----
}
else if (tv->v_type == VAR_FUNC)
name = tv->vval.v_string;
! if (name != NULL)
! {
! char_u fname_buf[FLEN_FIXED + 1];
! char_u *tofree = NULL;
! int error = FCERR_NONE;
! char_u *fname;
!
! // May need to translate <SNR>123_ to K_SNR.
! fname = fname_trans_sid(name, fname_buf, &tofree, &error);
! if (error != FCERR_NONE)
! res = FAIL;
! else
! res = call_by_name(fname, argcount, ectx, NULL);
! vim_free(tofree);
! }
!
! if (name == NULL || res == FAIL)
{
if (called_emsg == called_emsg_before)
semsg(_(e_unknownfunc),
*** ../vim-8.2.1540/src/testdir/test_vim9_script.vim 2020-08-29
13:39:12.578557657 +0200
--- src/testdir/test_vim9_script.vim 2020-08-29 17:40:31.947293841 +0200
***************
*** 1652,1657 ****
--- 1652,1661 ----
delete('Ximport.vim')
enddef
+ def s:RetSome(): string
+ return 'some'
+ enddef
+
" Not exported function that is referenced needs to be accessed by the
" script-local name.
def Test_vim9script_funcref()
***************
*** 1683,1688 ****
--- 1687,1695 ----
unlet g:result
delete('Xsort.vim')
delete('Xscript.vim')
+
+ let Funcref = function('s:RetSome')
+ assert_equal('some', Funcref())
enddef
" Check that when searching for "FilterFunc" it finds the import in the
*** ../vim-8.2.1540/src/version.c 2020-08-29 16:40:22.497472241 +0200
--- src/version.c 2020-08-29 17:46:07.397934553 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1541,
/**/
--
You cannot propel yourself forward by patting yourself on the back.
/// 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/202008291547.07TFlYkV2571477%40masaka.moolenaar.net.