Mercurial > vim
comparison src/userfunc.c @ 27611:e311a80f8cbe v8.2.4332
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Commit: https://github.com/vim/vim/commit/dce2441a603f2c9343a4a46091283a32420d80a2
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 8 20:35:30 2022 +0000
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Problem: Vim9: incomplete test for existing script variable in block.
Solution: Add a couple more tests. Fix uncovered problem.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 08 Feb 2022 21:45:03 +0100 |
parents | d504745607bc |
children | 5c4ab8d4472c |
comparison
equal
deleted
inserted
replaced
27610:81772f743738 | 27611:e311a80f8cbe |
---|---|
53 /* | 53 /* |
54 * Get one function argument. | 54 * Get one function argument. |
55 * If "argtypes" is not NULL also get the type: "arg: type" (:def function). | 55 * If "argtypes" is not NULL also get the type: "arg: type" (:def function). |
56 * If "types_optional" is TRUE a missing type is OK, use "any". | 56 * If "types_optional" is TRUE a missing type is OK, use "any". |
57 * If "evalarg" is not NULL use it to check for an already declared name. | 57 * If "evalarg" is not NULL use it to check for an already declared name. |
58 * If "eap" is not NULL use it to check for an already declared name. | |
58 * Return a pointer to after the type. | 59 * Return a pointer to after the type. |
59 * When something is wrong return "arg". | 60 * When something is wrong return "arg". |
60 */ | 61 */ |
61 static char_u * | 62 static char_u * |
62 one_function_arg( | 63 one_function_arg( |
63 char_u *arg, | 64 char_u *arg, |
64 garray_T *newargs, | 65 garray_T *newargs, |
65 garray_T *argtypes, | 66 garray_T *argtypes, |
66 int types_optional, | 67 int types_optional, |
67 evalarg_T *evalarg, | 68 evalarg_T *evalarg, |
69 exarg_T *eap, | |
68 int is_vararg, | 70 int is_vararg, |
69 int skip) | 71 int skip) |
70 { | 72 { |
71 char_u *p = arg; | 73 char_u *p = arg; |
72 char_u *arg_copy = NULL; | 74 char_u *arg_copy = NULL; |
85 } | 87 } |
86 | 88 |
87 // Vim9 script: cannot use script var name for argument. In function: also | 89 // Vim9 script: cannot use script var name for argument. In function: also |
88 // check local vars and arguments. | 90 // check local vars and arguments. |
89 if (!skip && argtypes != NULL && check_defined(arg, p - arg, | 91 if (!skip && argtypes != NULL && check_defined(arg, p - arg, |
90 evalarg == NULL ? NULL : evalarg->eval_cctx, TRUE) == FAIL) | 92 evalarg == NULL ? NULL : evalarg->eval_cctx, |
93 eap == NULL ? NULL : eap->cstack, TRUE) == FAIL) | |
91 return arg; | 94 return arg; |
92 | 95 |
93 if (newargs != NULL && ga_grow(newargs, 1) == FAIL) | 96 if (newargs != NULL && ga_grow(newargs, 1) == FAIL) |
94 return arg; | 97 return arg; |
95 if (newargs != NULL) | 98 if (newargs != NULL) |
208 int types_optional, // types optional if "argtypes" is not NULL | 211 int types_optional, // types optional if "argtypes" is not NULL |
209 evalarg_T *evalarg, // context or NULL | 212 evalarg_T *evalarg, // context or NULL |
210 int *varargs, | 213 int *varargs, |
211 garray_T *default_args, | 214 garray_T *default_args, |
212 int skip, | 215 int skip, |
213 exarg_T *eap, | 216 exarg_T *eap, // can be NULL |
214 garray_T *lines_to_free) | 217 garray_T *lines_to_free) |
215 { | 218 { |
216 int mustend = FALSE; | 219 int mustend = FALSE; |
217 char_u *arg; | 220 char_u *arg; |
218 char_u *p; | 221 char_u *p; |
277 goto err_ret; | 280 goto err_ret; |
278 } | 281 } |
279 | 282 |
280 arg = p; | 283 arg = p; |
281 p = one_function_arg(p, newargs, argtypes, types_optional, | 284 p = one_function_arg(p, newargs, argtypes, types_optional, |
282 evalarg, TRUE, skip); | 285 evalarg, eap, TRUE, skip); |
283 if (p == arg) | 286 if (p == arg) |
284 break; | 287 break; |
285 if (*skipwhite(p) == '=') | 288 if (*skipwhite(p) == '=') |
286 { | 289 { |
287 emsg(_(e_cannot_use_default_for_variable_arguments)); | 290 emsg(_(e_cannot_use_default_for_variable_arguments)); |
293 { | 296 { |
294 char_u *np; | 297 char_u *np; |
295 | 298 |
296 arg = p; | 299 arg = p; |
297 p = one_function_arg(p, newargs, argtypes, types_optional, | 300 p = one_function_arg(p, newargs, argtypes, types_optional, |
298 evalarg, FALSE, skip); | 301 evalarg, eap, FALSE, skip); |
299 if (p == arg) | 302 if (p == arg) |
300 break; | 303 break; |
301 | 304 |
302 // Recognize " = expr" but not " == expr". A lambda can have | 305 // Recognize " = expr" but not " == expr". A lambda can have |
303 // "(a = expr" but "(a == expr" and "(a =~ expr" are not a lambda. | 306 // "(a = expr" but "(a == expr" and "(a =~ expr" are not a lambda. |