Mercurial > vim
diff src/userfunc.c @ 20029:8fb1cf4c44d5 v8.2.0570
patch 8.2.0570: Vim9: no error when omitting type from argument
Commit: https://github.com/vim/vim/commit/6e949784be29bfaea6e49a9d8231481eae10fab6
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Apr 13 17:21:00 2020 +0200
patch 8.2.0570: Vim9: no error when omitting type from argument
Problem: Vim9: no error when omitting type from argument.
Solution: Enforce specifying argument types.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 13 Apr 2020 17:30:05 +0200 |
parents | c85d4e173cc9 |
children | 04ef2ccf2519 |
line wrap: on
line diff
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -64,14 +64,16 @@ func_tbl_get(void) } /* - * Get one function argument and an optional type: "arg: type". + * Get one function argument. + * If "argtypes" is not NULL also get the type: "arg: type". * Return a pointer to after the type. * When something is wrong return "arg". */ static char_u * one_function_arg(char_u *arg, garray_T *newargs, garray_T *argtypes, int skip) { - char_u *p = arg; + char_u *p = arg; + char_u *arg_copy = NULL; while (ASCII_ISALNUM(*p) || *p == '_') ++p; @@ -87,7 +89,6 @@ one_function_arg(char_u *arg, garray_T * return arg; if (newargs != NULL) { - char_u *arg_copy; int c; int i; @@ -119,14 +120,24 @@ one_function_arg(char_u *arg, garray_T * { char_u *type = NULL; + if (VIM_ISWHITE(*p) && *skipwhite(p) == ':') + { + semsg(_("E1059: No white space allowed before colon: %s"), + arg_copy == NULL ? arg : arg_copy); + p = skipwhite(p); + } if (*p == ':') { type = skipwhite(p + 1); p = skip_type(type); type = vim_strnsave(type, p - type); } - else if (*skipwhite(p) == ':') - emsg(_("E1059: No white space allowed before :")); + else if (*skipwhite(p) != '=') + { + semsg(_("E1077: Missing argument type for %s"), + arg_copy == NULL ? arg : arg_copy); + return arg; + } ((char_u **)argtypes->ga_data)[argtypes->ga_len++] = type; }