To: vim_dev@googlegroups.com Subject: Patch 8.2.2566 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2566 Problem: Vim9: Function name is not recognized. Solution: Change lookup_scriptvar() to also find function names. (closes #7770) Files: src/vim9script.c, src/evalvars.c, src/proto/evalvars.pro, src/ex_docmd.c, src/testdir/test_vim9_cmd.vim *** ../vim-8.2.2565/src/vim9script.c 2021-02-28 16:55:07.513026844 +0100 --- src/vim9script.c 2021-03-03 20:29:21.589579508 +0100 *************** *** 138,144 **** } eap->cmd = eap->arg; ! (void)find_ex_command(eap, NULL, lookup_scriptvar, NULL); switch (eap->cmdidx) { case CMD_let: --- 138,144 ---- } eap->cmd = eap->arg; ! (void)find_ex_command(eap, NULL, lookup_scriptitem, NULL); switch (eap->cmdidx) { case CMD_let: *** ../vim-8.2.2565/src/evalvars.c 2021-02-20 17:03:57.984112613 +0100 --- src/evalvars.c 2021-03-03 21:20:07.863051281 +0100 *************** *** 2788,2798 **** } /* ! * Look for "name[len]" in script-local variables. * Return OK when found, FAIL when not found. */ int ! lookup_scriptvar( char_u *name, size_t len, cctx_T *dummy UNUSED) --- 2788,2798 ---- } /* ! * Look for "name[len]" in script-local variables and functions. * Return OK when found, FAIL when not found. */ int ! lookup_scriptitem( char_u *name, size_t len, cctx_T *dummy UNUSED) *************** *** 2802,2807 **** --- 2802,2809 ---- char_u *p; int res; hashitem_T *hi; + int is_global = FALSE; + char_u *fname = name; if (ht == NULL) return FAIL; *************** *** 2824,2832 **** // if not script-local, then perhaps imported if (res == FAIL && find_imported(p, 0, NULL) != NULL) res = OK; - if (p != buffer) vim_free(p); return res; } --- 2826,2849 ---- // if not script-local, then perhaps imported if (res == FAIL && find_imported(p, 0, NULL) != NULL) res = OK; if (p != buffer) vim_free(p); + + if (res != OK) + { + // Find a function, so that a following "->" works. Skip "g:" before a + // function name. + // Do not check for an internal function, since it might also be a + // valid command, such as ":split" versuse "split()". + if (name[0] == 'g' && name[1] == ':') + { + is_global = TRUE; + fname = name + 2; + } + if (find_func(fname, is_global, NULL) != NULL) + res = OK; + } + return res; } *** ../vim-8.2.2565/src/proto/evalvars.pro 2021-02-20 17:03:57.984112613 +0100 --- src/proto/evalvars.pro 2021-03-03 20:29:06.457613907 +0100 *************** *** 61,67 **** dictitem_T *find_var(char_u *name, hashtab_T **htp, int no_autoload); dictitem_T *find_var_in_ht(hashtab_T *ht, int htname, char_u *varname, int no_autoload); hashtab_T *get_script_local_ht(void); ! int lookup_scriptvar(char_u *name, size_t len, cctx_T *dummy); hashtab_T *find_var_ht(char_u *name, char_u **varname); char_u *get_var_value(char_u *name); void new_script_vars(scid_T id); --- 61,67 ---- dictitem_T *find_var(char_u *name, hashtab_T **htp, int no_autoload); dictitem_T *find_var_in_ht(hashtab_T *ht, int htname, char_u *varname, int no_autoload); hashtab_T *get_script_local_ht(void); ! int lookup_scriptitem(char_u *name, size_t len, cctx_T *dummy); hashtab_T *find_var_ht(char_u *name, char_u **varname); char_u *get_var_value(char_u *name); void new_script_vars(scid_T id); *** ../vim-8.2.2565/src/ex_docmd.c 2021-02-19 21:42:51.544789771 +0100 --- src/ex_docmd.c 2021-03-03 20:29:16.097591981 +0100 *************** *** 1829,1835 **** if (ea.cmd == cmd + 1 && *cmd == '$') // should be "$VAR = val" --ea.cmd; ! p = find_ex_command(&ea, NULL, lookup_scriptvar, NULL); if (ea.cmdidx == CMD_SIZE) { char_u *ar = skip_range(ea.cmd, TRUE, NULL); --- 1829,1835 ---- if (ea.cmd == cmd + 1 && *cmd == '$') // should be "$VAR = val" --ea.cmd; ! p = find_ex_command(&ea, NULL, lookup_scriptitem, NULL); if (ea.cmdidx == CMD_SIZE) { char_u *ar = skip_range(ea.cmd, TRUE, NULL); *** ../vim-8.2.2565/src/testdir/test_vim9_cmd.vim 2021-02-17 14:52:10.539374448 +0100 --- src/testdir/test_vim9_cmd.vim 2021-03-03 20:45:10.859456879 +0100 *************** *** 371,376 **** --- 371,394 ---- MethodAfterLinebreak('foobar') assert_equal('foobar', getline(1)) bwipe! + + lines =<< trim END + vim9script + def Foo(): string + return '# some text' + enddef + + def Bar(F: func): string + return F() + enddef + + Foo + ->Bar() + ->setline(1) + END + CheckScriptSuccess(lines) + assert_equal('# some text', getline(1)) + bwipe! enddef def Test_method_call_whitespace() *** ../vim-8.2.2565/src/version.c 2021-03-03 17:58:12.009789245 +0100 --- src/version.c 2021-03-03 20:28:35.697683938 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2566, /**/ -- TERRY GILLIAM PLAYED: PATSY (ARTHUR'S TRUSTY STEED), THE GREEN KNIGHT SOOTHSAYER, BRIDGEKEEPER, SIR GAWAIN (THE FIRST TO BE KILLED BY THE RABBIT) "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///