1
0
forked from aniani/vim

patch 9.1.1013: Vim9: Regression caused by patch v9.1.0646

Problem:  Vim9: Regression caused by patch v9.1.0646
Solution: Translate the function name before invoking it in call()
          (Yegappan Lakshmanan)

fixes: #16430
closes: #16445

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yegappan Lakshmanan
2025-01-14 17:13:36 +01:00
committed by Christian Brabandt
parent 30377e0fe0
commit 6289f91591
8 changed files with 100 additions and 78 deletions

View File

@@ -8786,15 +8786,33 @@ option_set_callback_func(char_u *optval UNUSED, callback_T *optcb UNUSED)
vim_free(cb.cb_name);
free_tv(tv);
if (in_vim9script() && funcname && (vim_strchr(optval, '.') != NULL))
char_u *dot = NULL;
if (in_vim9script() && funcname
&& ((dot = vim_strchr(optval, '.')) != NULL))
{
// When a Vim9 imported function name is used, it is expanded by the
// call to get_callback() above to <SNR>_funcname. Revert the name to
// back to "import.funcname".
if (optcb->cb_free_name)
vim_free(optcb->cb_name);
optcb->cb_name = vim_strsave(optval);
optcb->cb_free_name = TRUE;
imported_T *import = find_imported(optval, dot - optval, FALSE);
if (import != NULL && SCRIPT_ID_VALID(import->imp_sid)
&& !(import->imp_flags & IMP_FLAGS_AUTOLOAD))
{
char_u fnamebuf[MAX_FUNC_NAME_LEN];
// Imported non-autoloaded function. Replace the import script
// name (import.funcname) with the script ID (<SNR>123_funcname)
vim_snprintf((char *)fnamebuf, sizeof(fnamebuf), "<SNR>%d_%s",
import->imp_sid, dot + 1);
optcb->cb_name = vim_strsave(fnamebuf);
optcb->cb_free_name = TRUE;
}
else
{
// Imported autoloaded function. Store the function name as
// "import.funcname".
optcb->cb_name = vim_strsave(optval);
optcb->cb_free_name = TRUE;
}
}
// when using Vim9 style "import.funcname" it needs to be expanded to
// "import#funcname".