Mercurial > vim
comparison src/userfunc.c @ 20339:7587d892c00c v8.2.0725
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Commit: https://github.com/vim/vim/commit/09689a02840be40fa7bb10b1921fb5bc5b2908f1
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat May 9 22:50:08 2020 +0200
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Problem: Vim9: cannot call a function declared later in Vim9 script.
Solution: Make two passes through the script file.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 09 May 2020 23:00:04 +0200 |
parents | 49b50843e725 |
children | 4c317d8c1051 |
comparison
equal
deleted
inserted
replaced
20338:ff4ae3f09307 | 20339:7587d892c00c |
---|---|
2376 /* | 2376 /* |
2377 * ":function" also supporting nested ":def". | 2377 * ":function" also supporting nested ":def". |
2378 * Returns a pointer to the function or NULL if no function defined. | 2378 * Returns a pointer to the function or NULL if no function defined. |
2379 */ | 2379 */ |
2380 ufunc_T * | 2380 ufunc_T * |
2381 def_function(exarg_T *eap, char_u *name_arg, void *context) | 2381 def_function(exarg_T *eap, char_u *name_arg, void *context, int compile) |
2382 { | 2382 { |
2383 char_u *theline; | 2383 char_u *theline; |
2384 char_u *line_to_free = NULL; | 2384 char_u *line_to_free = NULL; |
2385 int j; | 2385 int j; |
2386 int c; | 2386 int c; |
3239 else | 3239 else |
3240 { | 3240 { |
3241 p = ret_type; | 3241 p = ret_type; |
3242 fp->uf_ret_type = parse_type(&p, &fp->uf_type_list); | 3242 fp->uf_ret_type = parse_type(&p, &fp->uf_type_list); |
3243 } | 3243 } |
3244 SOURCING_LNUM = lnum_save; | |
3244 } | 3245 } |
3245 | 3246 |
3246 fp->uf_lines = newlines; | 3247 fp->uf_lines = newlines; |
3247 if ((flags & FC_CLOSURE) != 0) | 3248 if ((flags & FC_CLOSURE) != 0) |
3248 { | 3249 { |
3271 fp->uf_flags |= FC_EXPORT; | 3272 fp->uf_flags |= FC_EXPORT; |
3272 // let ex_export() know the export worked. | 3273 // let ex_export() know the export worked. |
3273 is_export = FALSE; | 3274 is_export = FALSE; |
3274 } | 3275 } |
3275 | 3276 |
3276 // ":def Func()" needs to be compiled | 3277 // ":def Func()" may need to be compiled |
3277 if (eap->cmdidx == CMD_def) | 3278 if (eap->cmdidx == CMD_def && compile) |
3278 compile_def_function(fp, FALSE, context); | 3279 compile_def_function(fp, FALSE, context); |
3279 | 3280 |
3280 goto ret_free; | 3281 goto ret_free; |
3281 | 3282 |
3282 erret: | 3283 erret: |
3302 * ":function" | 3303 * ":function" |
3303 */ | 3304 */ |
3304 void | 3305 void |
3305 ex_function(exarg_T *eap) | 3306 ex_function(exarg_T *eap) |
3306 { | 3307 { |
3307 def_function(eap, NULL, NULL); | 3308 (void)def_function(eap, NULL, NULL, TRUE); |
3308 } | 3309 } |
3309 | 3310 |
3310 /* | 3311 /* |
3311 * Return 5 if "p" starts with "<SID>" or "<SNR>" (ignoring case). | 3312 * Return 5 if "p" starts with "<SID>" or "<SNR>" (ignoring case). |
3312 * Return 2 if "p" starts with "s:". | 3313 * Return 2 if "p" starts with "s:". |