Patch 8.2.2682

4 views
Skip to first unread message

Bram Moolenaar

unread,
Apr 1, 2021, 6:58:50 AM4/1/21
to vim...@googlegroups.com

Patch 8.2.2682
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.
Files: src/vim9compile.c, src/vim9script.c,
src/testdir/test_vim9_script.vim


*** ../vim-8.2.2681/src/vim9compile.c 2021-03-29 22:14:45.604788424 +0200
--- src/vim9compile.c 2021-03-31 22:21:46.938068985 +0200
***************
*** 2720,2730 ****
cctx, TRUE);
*p = cc;
p = skipwhite(p);

- // TODO: what if it is a function?
if (idx < 0)
return FAIL;
! *end = p;

generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
import->imp_sid,
--- 2720,2736 ----
cctx, TRUE);
*p = cc;
p = skipwhite(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,
import->imp_sid,
*** ../vim-8.2.2681/src/vim9script.c 2021-03-31 21:07:21.312591129 +0200
--- src/vim9script.c 2021-04-01 12:50:54.712287226 +0200
***************
*** 298,305 ****
svar_T *sv;
scriptitem_T *script = SCRIPT_ITEM(sid);

! // find name in "script"
! // TODO: also find script-local user function
idx = get_script_item_idx(sid, name, 0, cctx);
if (idx >= 0)
{
--- 298,304 ----
svar_T *sv;
scriptitem_T *script = SCRIPT_ITEM(sid);

! // Find name in "script".
idx = get_script_item_idx(sid, name, 0, cctx);
if (idx >= 0)
{
***************
*** 341,346 ****
--- 340,352 ----
semsg(_(e_item_not_found_in_script_str), name);
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;
*** ../vim-8.2.2681/src/testdir/test_vim9_script.vim 2021-03-31 21:07:21.312591129 +0200
--- src/testdir/test_vim9_script.vim 2021-04-01 12:53:07.675968108 +0200
***************
*** 1623,1628 ****
--- 1623,1632 ----
export def FastSort(): list<number>
return range(5)->sort(Compare)
enddef
+
+ export def GetString(arg: string): string
+ return arg
+ enddef
END
writefile(sortlines, 'Xsort.vim')

***************
*** 1633,1638 ****
--- 1637,1655 ----
g:result = FastSort()
enddef
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
writefile(lines, 'Xscript.vim')

*** ../vim-8.2.2681/src/version.c 2021-03-31 21:47:30.255015197 +0200
--- src/version.c 2021-04-01 12:54:30.463767896 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2682,
/**/

--
Those who live by the sword get shot by those who don't.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages