diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-03-06 21:01:09 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-03-06 21:01:09 +0100 |
commit | 6914e87d3c0387fdcbb117a39e1f6d1fac0ee2e3 (patch) | |
tree | 70c8eac58264c58d4fa50f3d8aa740619e84b73b | |
parent | 04947cc6ed313b6b99889c27d008c68a373df634 (diff) | |
download | vim-git-6914e87d3c0387fdcbb117a39e1f6d1fac0ee2e3.tar.gz |
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't workv8.2.2575
Problem: Vim9: a function name with "->" in the next line doesn't work.
Solution: Recognize a function name by itself. (closes #7770)
-rw-r--r-- | src/testdir/test_vim9_cmd.vim | 19 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 25 |
3 files changed, 43 insertions, 3 deletions
diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim index f638c84b0..dd6e966de 100644 --- a/src/testdir/test_vim9_cmd.vim +++ b/src/testdir/test_vim9_cmd.vim @@ -357,6 +357,25 @@ def Test_method_call_linebreak() lines =<< trim END new + def Foo(): string + return 'the text' + enddef + def Bar(F: func): string + return F() + enddef + def Test() + Foo + ->Bar() + ->setline(1) + enddef + Test() + assert_equal('the text', getline(1)) + bwipe! + END + CheckDefAndScriptSuccess(lines) + + lines =<< trim END + new g:shortlist ->copy() ->setline(1) diff --git a/src/version.c b/src/version.c index 278f77bc6..48f3faae1 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2575, +/**/ 2574, /**/ 2573, diff --git a/src/vim9compile.c b/src/vim9compile.c index f6d1fb3d8..c78106023 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -387,6 +387,26 @@ variable_exists(char_u *name, size_t len, cctx_T *cctx) } /* + * 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, vartype_T type1, vartype_T type2) } 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) { |