diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-02-21 13:13:50 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-02-21 13:13:50 +0000 |
commit | c2f17f7e64bb1bf872dbc6f3b8f0d8751e275287 (patch) | |
tree | 229b6c9923d3eb383f9dbd254104a661c348b42d /src/userfunc.c | |
parent | 0f6e28f686dbb59ab3b562408ab9b2234797b9b1 (diff) | |
download | vim-git-c2f17f7e64bb1bf872dbc6f3b8f0d8751e275287.tar.gz |
patch 8.2.4429: using script-local function from the wrong scriptv8.2.4429
Problem: Using script-local function from the wrong script when using a
partial. (Yegappan Lakshmanan)
Solution: Include the script ID in the partial name.
Diffstat (limited to 'src/userfunc.c')
-rw-r--r-- | src/userfunc.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/userfunc.c b/src/userfunc.c index 3e0d021ba..3a66d2732 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -1958,17 +1958,29 @@ find_func_even_dead(char_u *name, int flags) if ((flags & FFED_IS_GLOBAL) == 0) { - int find_script_local = in_vim9script() && eval_isnamec1(*name) - && (name[1] != ':' || *name == 's'); - - if (find_script_local) + // Find script-local function before global one. + if (in_vim9script() && eval_isnamec1(*name) + && (name[1] != ':' || *name == 's')) { - // Find script-local function before global one. func = find_func_with_sid(name[0] == 's' && name[1] == ':' ? name + 2 : name, current_sctx.sc_sid); if (func != NULL) return func; } + if (in_vim9script() && STRNCMP(name, "<SNR>", 5) == 0) + { + char_u *p = name + 5; + long sid; + + // printable "<SNR>123_Name" form + sid = getdigits(&p); + if (*p == '_') + { + func = find_func_with_sid(p + 1, (int)sid); + if (func != NULL) + return func; + } + } } if ((flags & FFED_NO_GLOBAL) == 0) @@ -4068,6 +4080,23 @@ get_scriptlocal_funcname(char_u *funcname) } /* + * Return script-local "fname" with the 3-byte sequence replaced by + * printable <SNR> in allocated memory. + */ + char_u * +alloc_printable_func_name(char_u *fname) +{ + char_u *n = alloc(STRLEN(fname + 3) + 6); + + if (n != NULL) + { + STRCPY(n, "<SNR>"); + STRCPY(n + 5, fname + 3); + } + return n; +} + +/* * Call trans_function_name(), except that a lambda is returned as-is. * Returns the name in allocated memory. */ |