comparison 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
comparison
equal deleted inserted replaced
20028:f0fb61802fe7 20029:8fb1cf4c44d5
62 { 62 {
63 return &func_hashtab; 63 return &func_hashtab;
64 } 64 }
65 65
66 /* 66 /*
67 * Get one function argument and an optional type: "arg: type". 67 * Get one function argument.
68 * If "argtypes" is not NULL also get the type: "arg: type".
68 * Return a pointer to after the type. 69 * Return a pointer to after the type.
69 * When something is wrong return "arg". 70 * When something is wrong return "arg".
70 */ 71 */
71 static char_u * 72 static char_u *
72 one_function_arg(char_u *arg, garray_T *newargs, garray_T *argtypes, int skip) 73 one_function_arg(char_u *arg, garray_T *newargs, garray_T *argtypes, int skip)
73 { 74 {
74 char_u *p = arg; 75 char_u *p = arg;
76 char_u *arg_copy = NULL;
75 77
76 while (ASCII_ISALNUM(*p) || *p == '_') 78 while (ASCII_ISALNUM(*p) || *p == '_')
77 ++p; 79 ++p;
78 if (arg == p || isdigit(*arg) 80 if (arg == p || isdigit(*arg)
79 || (p - arg == 9 && STRNCMP(arg, "firstline", 9) == 0) 81 || (p - arg == 9 && STRNCMP(arg, "firstline", 9) == 0)
85 } 87 }
86 if (newargs != NULL && ga_grow(newargs, 1) == FAIL) 88 if (newargs != NULL && ga_grow(newargs, 1) == FAIL)
87 return arg; 89 return arg;
88 if (newargs != NULL) 90 if (newargs != NULL)
89 { 91 {
90 char_u *arg_copy;
91 int c; 92 int c;
92 int i; 93 int i;
93 94
94 c = *p; 95 c = *p;
95 *p = NUL; 96 *p = NUL;
117 // get any type from "arg: type" 118 // get any type from "arg: type"
118 if (argtypes != NULL && ga_grow(argtypes, 1) == OK) 119 if (argtypes != NULL && ga_grow(argtypes, 1) == OK)
119 { 120 {
120 char_u *type = NULL; 121 char_u *type = NULL;
121 122
123 if (VIM_ISWHITE(*p) && *skipwhite(p) == ':')
124 {
125 semsg(_("E1059: No white space allowed before colon: %s"),
126 arg_copy == NULL ? arg : arg_copy);
127 p = skipwhite(p);
128 }
122 if (*p == ':') 129 if (*p == ':')
123 { 130 {
124 type = skipwhite(p + 1); 131 type = skipwhite(p + 1);
125 p = skip_type(type); 132 p = skip_type(type);
126 type = vim_strnsave(type, p - type); 133 type = vim_strnsave(type, p - type);
127 } 134 }
128 else if (*skipwhite(p) == ':') 135 else if (*skipwhite(p) != '=')
129 emsg(_("E1059: No white space allowed before :")); 136 {
137 semsg(_("E1077: Missing argument type for %s"),
138 arg_copy == NULL ? arg : arg_copy);
139 return arg;
140 }
130 ((char_u **)argtypes->ga_data)[argtypes->ga_len++] = type; 141 ((char_u **)argtypes->ga_data)[argtypes->ga_len++] = type;
131 } 142 }
132 143
133 return p; 144 return p;
134 } 145 }