Mercurial > vim
diff src/vim9compile.c @ 24067:780dec2ffa6b v8.2.2575
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Commit: https://github.com/vim/vim/commit/6914e87d3c0387fdcbb117a39e1f6d1fac0ee2e3
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 6 21:01:09 2021 +0100
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Problem: Vim9: a function name with "->" in the next line doesn't work.
Solution: Recognize a function name by itself. (closes https://github.com/vim/vim/issues/7770)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 06 Mar 2021 21:15:02 +0100 |
parents | d6489b4eb14e |
children | 23c692a4bc36 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -387,6 +387,26 @@ variable_exists(char_u *name, size_t len } /* + * Return TRUE if "name" is a local variable, argument, script variable, + * imported or function. + */ + static int +item_exists(char_u *name, size_t len, cctx_T *cctx) +{ + int is_global; + + if (variable_exists(name, len, cctx)) + return TRUE; + + // 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()". + is_global = (name[0] == 'g' && name[1] == ':'); + return find_func(is_global ? name + 2 : name, is_global, cctx) != NULL; +} + +/* * Check if "p[len]" is already defined, either in script "import_sid" or in * compilation context "cctx". "cctx" is NULL at the script level. * Does not check the global namespace. @@ -728,7 +748,7 @@ get_compare_isn(exprtype_T exprtype, var } else if (type1 == VAR_ANY || type2 == VAR_ANY || ((type1 == VAR_NUMBER || type1 == VAR_FLOAT) - && (type2 == VAR_NUMBER || type2 ==VAR_FLOAT))) + && (type2 == VAR_NUMBER || type2 == VAR_FLOAT))) isntype = ISN_COMPAREANY; if ((exprtype == EXPR_IS || exprtype == EXPR_ISNOT) @@ -8399,8 +8419,7 @@ compile_def_function( } } p = find_ex_command(&ea, NULL, starts_with_colon ? NULL - : (int (*)(char_u *, size_t, cctx_T *))variable_exists, - &cctx); + : (int (*)(char_u *, size_t, cctx_T *))item_exists, &cctx); if (p == NULL) {