patch 8.2.1399: Vim9: may find imported item in wrong script
Problem: Vim9: may find imported item in wrong script.
Solution: When looking up script-local function use the embedded script ID.
(issue #6644)
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 5f76bc2..a47d3d9 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2548,12 +2548,10 @@
imported_T *
find_imported(char_u *name, size_t len, cctx_T *cctx)
{
- scriptitem_T *si;
int idx;
if (current_sctx.sc_sid <= 0)
return NULL;
- si = SCRIPT_ITEM(current_sctx.sc_sid);
if (cctx != NULL)
for (idx = 0; idx < cctx->ctx_imports.ga_len; ++idx)
{
@@ -2566,6 +2564,15 @@
return import;
}
+ return find_imported_in_script(name, len, current_sctx.sc_sid);
+}
+
+ imported_T *
+find_imported_in_script(char_u *name, size_t len, int sid)
+{
+ scriptitem_T *si = SCRIPT_ITEM(sid);
+ int idx;
+
for (idx = 0; idx < si->sn_imports.ga_len; ++idx)
{
imported_T *import = ((imported_T *)si->sn_imports.ga_data) + idx;