mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Problem: Vim9: cannot find Name.Func from "import * as Name". (Alexander Goussas) Solution: When no variable found try finding a function. (closes #8045) Check that the function was exported.
This commit is contained in:
@@ -1623,6 +1623,10 @@ def Test_vim9script_funcref()
|
|||||||
export def FastSort(): list<number>
|
export def FastSort(): list<number>
|
||||||
return range(5)->sort(Compare)
|
return range(5)->sort(Compare)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
export def GetString(arg: string): string
|
||||||
|
return arg
|
||||||
|
enddef
|
||||||
END
|
END
|
||||||
writefile(sortlines, 'Xsort.vim')
|
writefile(sortlines, 'Xsort.vim')
|
||||||
|
|
||||||
@@ -1633,6 +1637,19 @@ def Test_vim9script_funcref()
|
|||||||
g:result = FastSort()
|
g:result = FastSort()
|
||||||
enddef
|
enddef
|
||||||
Test()
|
Test()
|
||||||
|
|
||||||
|
# using a function imported with "as"
|
||||||
|
import * as anAlias from './Xsort.vim'
|
||||||
|
assert_equal('yes', anAlias.GetString('yes'))
|
||||||
|
|
||||||
|
# using the function from a compiled function
|
||||||
|
def TestMore(): string
|
||||||
|
return anAlias.GetString('text')
|
||||||
|
enddef
|
||||||
|
assert_equal('text', TestMore())
|
||||||
|
|
||||||
|
# error when using a function that isn't exported
|
||||||
|
assert_fails('anAlias.Compare(1, 2)', 'E1049:')
|
||||||
END
|
END
|
||||||
writefile(lines, 'Xscript.vim')
|
writefile(lines, 'Xscript.vim')
|
||||||
|
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2682,
|
||||||
/**/
|
/**/
|
||||||
2681,
|
2681,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -2720,12 +2720,18 @@ compile_load_scriptvar(
|
|||||||
cctx, TRUE);
|
cctx, TRUE);
|
||||||
*p = cc;
|
*p = cc;
|
||||||
p = skipwhite(p);
|
p = skipwhite(p);
|
||||||
|
|
||||||
// TODO: what if it is a function?
|
|
||||||
if (idx < 0)
|
|
||||||
return FAIL;
|
|
||||||
*end = p;
|
*end = p;
|
||||||
|
|
||||||
|
if (idx < 0)
|
||||||
|
{
|
||||||
|
if (*p == '(' && ufunc != NULL)
|
||||||
|
{
|
||||||
|
generate_PUSHFUNC(cctx, ufunc->uf_name, import->imp_type);
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
|
generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
|
||||||
import->imp_sid,
|
import->imp_sid,
|
||||||
idx,
|
idx,
|
||||||
|
@@ -298,8 +298,7 @@ find_exported(
|
|||||||
svar_T *sv;
|
svar_T *sv;
|
||||||
scriptitem_T *script = SCRIPT_ITEM(sid);
|
scriptitem_T *script = SCRIPT_ITEM(sid);
|
||||||
|
|
||||||
// find name in "script"
|
// Find name in "script".
|
||||||
// TODO: also find script-local user function
|
|
||||||
idx = get_script_item_idx(sid, name, 0, cctx);
|
idx = get_script_item_idx(sid, name, 0, cctx);
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
{
|
{
|
||||||
@@ -341,6 +340,13 @@ find_exported(
|
|||||||
semsg(_(e_item_not_found_in_script_str), name);
|
semsg(_(e_item_not_found_in_script_str), name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
else if (((*ufunc)->uf_flags & FC_EXPORT) == 0)
|
||||||
|
{
|
||||||
|
if (verbose)
|
||||||
|
semsg(_(e_item_not_exported_in_script_str), name);
|
||||||
|
*ufunc = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return idx;
|
return idx;
|
||||||
|
Reference in New Issue
Block a user