To: vim_dev@googlegroups.com Subject: Patch 8.2.2575 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2575 Problem: Vim9: a function name with "->" in the next line doesn't work. Solution: Recognize a function name by itself. (closes #7770) Files: src/vim9compile.c, src/testdir/test_vim9_cmd.vim *** ../vim-8.2.2574/src/vim9compile.c 2021-03-05 21:35:44.272045238 +0100 --- src/vim9compile.c 2021-03-06 21:00:23.109205265 +0100 *************** *** 387,392 **** --- 387,412 ---- } /* + * 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,734 **** } else if (type1 == VAR_ANY || type2 == VAR_ANY || ((type1 == VAR_NUMBER || type1 == VAR_FLOAT) ! && (type2 == VAR_NUMBER || type2 ==VAR_FLOAT))) isntype = ISN_COMPAREANY; if ((exprtype == EXPR_IS || exprtype == EXPR_ISNOT) --- 748,754 ---- } else if (type1 == VAR_ANY || type2 == VAR_ANY || ((type1 == VAR_NUMBER || type1 == VAR_FLOAT) ! && (type2 == VAR_NUMBER || type2 == VAR_FLOAT))) isntype = ISN_COMPAREANY; if ((exprtype == EXPR_IS || exprtype == EXPR_ISNOT) *************** *** 8399,8406 **** } } p = find_ex_command(&ea, NULL, starts_with_colon ? NULL ! : (int (*)(char_u *, size_t, cctx_T *))variable_exists, ! &cctx); if (p == NULL) { --- 8419,8425 ---- } } p = find_ex_command(&ea, NULL, starts_with_colon ? NULL ! : (int (*)(char_u *, size_t, cctx_T *))item_exists, &cctx); if (p == NULL) { *** ../vim-8.2.2574/src/testdir/test_vim9_cmd.vim 2021-03-03 21:22:37.178739531 +0100 --- src/testdir/test_vim9_cmd.vim 2021-03-06 20:59:41.693317650 +0100 *************** *** 357,362 **** --- 357,381 ---- 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) *** ../vim-8.2.2574/src/version.c 2021-03-06 19:26:42.431369337 +0100 --- src/version.c 2021-03-06 20:54:36.630158014 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2575, /**/ -- A M00se once bit my sister ... "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 ///