To: vim_dev@googlegroups.com Subject: Patch 8.2.2298 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2298 Problem: Vim9: comment right after "(" of function not recognized. Solution: Do not skip over white space before calling get_function_args(). (closes #7613) Files: src/userfunc.c, src/proto/userfunc.pro, src/testdir/test_vim9_func.vim *** ../vim-8.2.2297/src/userfunc.c 2021-01-01 19:17:52.293976798 +0100 --- src/userfunc.c 2021-01-04 14:07:55.894111391 +0100 *************** *** 154,162 **** /* * Get function arguments. * "argp" is advanced just after "endchar". */ ! int get_function_args( char_u **argp, char_u endchar, --- 154,163 ---- /* * Get function arguments. + * "argp" should point to just after the "(", possibly to white space. * "argp" is advanced just after "endchar". */ ! static int get_function_args( char_u **argp, char_u endchar, *************** *** 170,181 **** char_u **line_to_free) { int mustend = FALSE; ! char_u *arg = *argp; ! char_u *p = arg; int c; int any_default = FALSE; char_u *expr; ! char_u *whitep = arg; if (newargs != NULL) ga_init2(newargs, (int)sizeof(char_u *), 3); --- 171,182 ---- char_u **line_to_free) { int mustend = FALSE; ! char_u *arg; ! char_u *p; int c; int any_default = FALSE; char_u *expr; ! char_u *whitep = *argp; if (newargs != NULL) ga_init2(newargs, (int)sizeof(char_u *), 3); *************** *** 190,195 **** --- 191,198 ---- /* * Isolate the arguments: "arg1, arg2, ...)" */ + arg = skipwhite(*argp); + p = arg; while (*p != endchar) { while (eap != NULL && eap->getline != NULL *************** *** 548,554 **** // First, check if this is really a lambda expression. "->" or "=>" must // be found after the arguments. ! s = skipwhite(*arg + 1); ret = get_function_args(&s, equal_arrow ? ')' : '-', NULL, types_optional ? &argtypes : NULL, types_optional, NULL, NULL, TRUE, NULL, NULL); --- 551,557 ---- // First, check if this is really a lambda expression. "->" or "=>" must // be found after the arguments. ! s = *arg + 1; ret = get_function_args(&s, equal_arrow ? ')' : '-', NULL, types_optional ? &argtypes : NULL, types_optional, NULL, NULL, TRUE, NULL, NULL); *************** *** 564,570 **** pnewargs = &newargs; else pnewargs = NULL; ! *arg = skipwhite(*arg + 1); ret = get_function_args(arg, equal_arrow ? ')' : '-', pnewargs, types_optional ? &argtypes : NULL, types_optional, &varargs, NULL, FALSE, NULL, NULL); --- 567,573 ---- pnewargs = &newargs; else pnewargs = NULL; ! *arg += 1; ret = get_function_args(arg, equal_arrow ? ')' : '-', pnewargs, types_optional ? &argtypes : NULL, types_optional, &varargs, NULL, FALSE, NULL, NULL); *************** *** 2964,2969 **** --- 2967,2973 ---- int is_global = FALSE; char_u *p; char_u *arg; + char_u *whitep; char_u *line_arg = NULL; garray_T newargs; garray_T argtypes; *************** *** 3159,3165 **** if (vim_strchr(p, '(') != NULL) p = vim_strchr(p, '('); } - p = skipwhite(p + 1); // In Vim9 script only global functions can be redefined. if (vim9script && eap->forceit && !is_global) --- 3163,3168 ---- *************** *** 3199,3209 **** --- 3202,3214 ---- // This may get more lines and make the pointers into the first line // invalid. + ++p; if (get_function_args(&p, ')', &newargs, eap->cmdidx == CMD_def ? &argtypes : NULL, FALSE, &varargs, &default_args, eap->skip, eap, &line_to_free) == FAIL) goto errret_2; + whitep = p; if (eap->cmdidx == CMD_def) { *************** *** 3215,3220 **** --- 3220,3226 ---- if (p > ret_type) { ret_type = vim_strnsave(ret_type, p - ret_type); + whitep = p; p = skipwhite(p); } else *************** *** 3229,3234 **** --- 3235,3241 ---- // find extra arguments "range", "dict", "abort" and "closure" for (;;) { + whitep = p; p = skipwhite(p); if (STRNCMP(p, "range", 5) == 0) { *************** *** 3267,3273 **** else if (*p != NUL && !(*p == '"' && (!vim9script || eap->cmdidx == CMD_function) && eap->cmdidx != CMD_def) ! && !(*p == '#' && (vim9script || eap->cmdidx == CMD_def)) && !eap->skip && !did_emsg) semsg(_(e_trailing_arg), p); --- 3274,3281 ---- else if (*p != NUL && !(*p == '"' && (!vim9script || eap->cmdidx == CMD_function) && eap->cmdidx != CMD_def) ! && !(VIM_ISWHITE(*whitep) && *p == '#' ! && (vim9script || eap->cmdidx == CMD_def)) && !eap->skip && !did_emsg) semsg(_(e_trailing_arg), p); *** ../vim-8.2.2297/src/proto/userfunc.pro 2020-12-22 17:35:50.043978116 +0100 --- src/proto/userfunc.pro 2021-01-04 13:55:31.112146408 +0100 *************** *** 1,7 **** /* userfunc.c */ void func_init(void); hashtab_T *func_tbl_get(void); - int get_function_args(char_u **argp, char_u endchar, garray_T *newargs, garray_T *argtypes, int types_optional, int *varargs, garray_T *default_args, int skip, exarg_T *eap, char_u **line_to_free); char_u *get_lambda_name(void); char_u *register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state); int get_lambda_tv(char_u **arg, typval_T *rettv, int types_optional, evalarg_T *evalarg); --- 1,6 ---- *** ../vim-8.2.2297/src/testdir/test_vim9_func.vim 2021-01-03 13:09:48.226390595 +0100 --- src/testdir/test_vim9_func.vim 2021-01-04 14:08:48.829951149 +0100 *************** *** 241,246 **** --- 241,282 ---- delfunc g:Func enddef + def FuncWithComment( # comment + a: number, #comment + b: bool, # comment + c: string) #comment + assert_equal(4, a) + assert_equal(true, b) + assert_equal('yes', c) + enddef + + def Test_func_with_comments() + FuncWithComment(4, true, 'yes') + + var lines =<< trim END + def Func(# comment + arg: string) + enddef + END + CheckScriptFailure(lines, 'E125:', 1) + + lines =<< trim END + def Func( + arg: string# comment + ) + enddef + END + CheckScriptFailure(lines, 'E475:', 2) + + lines =<< trim END + def Func( + arg: string + )# comment + enddef + END + CheckScriptFailure(lines, 'E488:', 3) + enddef + def Test_nested_function() def Nested(arg: string): string return 'nested ' .. arg *** ../vim-8.2.2297/src/version.c 2021-01-04 13:37:50.251107339 +0100 --- src/version.c 2021-01-04 14:09:09.749887505 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2298, /**/ -- From "know your smileys": % Bike accident. A bit far-fetched, I suppose; although... o _ _ _ _o /\_ _ \\o (_)\__/o (_) _< \_ _>(_) (_)/<_ \_| \ _|/' \/ (_)>(_) (_) (_) (_) (_)' _\o_ /// 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 ///