Patch 8.2.2735
Problem: Vim9: function reference found with prefix, not without.
Solution: Also find function reference without prefix.
Files: src/vim9compile.c, src/testdir/test_vim9_expr.vim
*** ../vim-8.2.2734/src/vim9compile.c 2021-04-07 21:21:09.473817695 +0200
--- src/vim9compile.c 2021-04-07 21:55:49.619956068 +0200
***************
*** 2889,2899 ****
if (*(*arg + 1) == ':')
{
- // load namespaced variable
if (end <= *arg + 2)
{
isntype_T isn_type;
switch (**arg)
{
case 'g': isn_type = ISN_LOADGDICT; break;
--- 2889,2899 ----
if (*(*arg + 1) == ':')
{
if (end <= *arg + 2)
{
isntype_T isn_type;
+ // load dictionary of namespace
switch (**arg)
{
case 'g': isn_type = ISN_LOADGDICT; break;
***************
*** 2912,2917 ****
--- 2912,2918 ----
{
isntype_T isn_type = ISN_DROP;
+ // load namespaced variable
name = vim_strnsave(*arg + 2, end - (*arg + 2));
if (name == NULL)
return FAIL;
***************
*** 2920,2930 ****
{
case 'v': res = generate_LOADV(cctx, name, error);
break;
! case 's': res = compile_load_scriptvar(cctx, name,
NULL, &end, error);
break;
case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
! isn_type = ISN_LOADG;
else
{
isn_type = ISN_LOADAUTO;
--- 2921,2941 ----
{
case 'v': res = generate_LOADV(cctx, name, error);
break;
! case 's': if (is_expr && ASCII_ISUPPER(*name)
! && find_func(name, FALSE, cctx) != NULL)
! res = generate_funcref(cctx, name);
! else
! res = compile_load_scriptvar(cctx, name,
NULL, &end, error);
break;
case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
! {
! if (is_expr && ASCII_ISUPPER(*name)
! && find_func(name, FALSE, cctx) != NULL)
! res = generate_funcref(cctx, name);
! else
! isn_type = ISN_LOADG;
! }
else
{
isn_type = ISN_LOADAUTO;
***************
*** 2945,2951 ****
{
// Global, Buffer-local, Window-local and Tabpage-local
// variables can be defined later, thus we don't check if it
! // exists, give error at runtime.
res = generate_LOAD(cctx, isn_type, 0, name, &t_any);
}
}
--- 2956,2962 ----
{
// Global, Buffer-local, Window-local and Tabpage-local
// variables can be defined later, thus we don't check if it
! // exists, give an error at runtime.
res = generate_LOAD(cctx, isn_type, 0, name, &t_any);
}
}
***************
*** 2988,2997 ****
res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE);
// When evaluating an expression and the name starts with an
! // uppercase letter or "x:" it can be a user defined function.
! // TODO: this is just guessing
! if (res == FAIL && is_expr
! && (ASCII_ISUPPER(*name) || name[1] == ':'))
res = generate_funcref(cctx, name);
}
}
--- 2999,3007 ----
res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE);
// When evaluating an expression and the name starts with an
! // uppercase letter it can be a user defined function.
! // generate_funcref() will fail if the function can't be found.
! if (res == FAIL && is_expr && ASCII_ISUPPER(*name))
res = generate_funcref(cctx, name);
}
}
*** ../vim-8.2.2734/src/testdir/test_vim9_expr.vim 2021-04-07
21:21:09.477817687 +0200
--- src/testdir/test_vim9_expr.vim 2021-04-07 21:55:01.260087895 +0200
***************
*** 2102,2107 ****
--- 2102,2130 ----
assert_equal(123, FuncRef())
END
CheckDefAndScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ func g:GlobalFunc()
+ return 'global'
+ endfunc
+ func s:ScriptFunc()
+ return 'script'
+ endfunc
+ def Test()
+ var Ref = g:GlobalFunc
+ assert_equal('global', Ref())
+ Ref = GlobalFunc
+ assert_equal('global', Ref())
+
+ Ref = s:ScriptFunc
+ assert_equal('script', Ref())
+ Ref = ScriptFunc
+ assert_equal('script', Ref())
+ enddef
+ Test()
+ END
+ CheckScriptSuccess(lines)
enddef
let g:test_space_dict = {'': 'empty', ' ': 'space'}
*** ../vim-8.2.2734/src/version.c 2021-04-07 21:21:09.477817687 +0200
--- src/version.c 2021-04-07 21:52:59.672421236 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2735,
/**/
--
hundred-and-one symptoms of being an internet addict:
86. E-mail Deficiency Depression (EDD) forces you to e-mail yourself.
/// 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/202104071958.137Jwvmn3690959%40masaka.moolenaar.net.