Mercurial > vim
comparison src/vim9compile.c @ 26323:3841da4eac23 v8.2.3692
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Commit: https://github.com/vim/vim/commit/38453528c3372293d70c8e85471a6188749ff331
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Nov 28 22:00:12 2021 +0000
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Problem: Vim9: cannot use :func inside a :def function.
Solution: Make it work.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 28 Nov 2021 23:15:03 +0100 |
parents | 36361f080ffd |
children | 4044306e3836 |
comparison
equal
deleted
inserted
replaced
26322:931db05edfa7 | 26323:3841da4eac23 |
---|---|
1673 garray_T *stack = &cctx->ctx_type_stack; | 1673 garray_T *stack = &cctx->ctx_type_stack; |
1674 | 1674 |
1675 RETURN_OK_IF_SKIP(cctx); | 1675 RETURN_OK_IF_SKIP(cctx); |
1676 if ((isn = generate_instr(cctx, ISN_FUNCREF)) == NULL) | 1676 if ((isn = generate_instr(cctx, ISN_FUNCREF)) == NULL) |
1677 return FAIL; | 1677 return FAIL; |
1678 isn->isn_arg.funcref.fr_func = ufunc->uf_dfunc_idx; | 1678 if (ufunc->uf_def_status == UF_NOT_COMPILED) |
1679 isn->isn_arg.funcref.fr_func_name = vim_strsave(ufunc->uf_name); | |
1680 else | |
1681 isn->isn_arg.funcref.fr_dfunc_idx = ufunc->uf_dfunc_idx; | |
1679 cctx->ctx_has_closure = 1; | 1682 cctx->ctx_has_closure = 1; |
1680 | 1683 |
1681 // If the referenced function is a closure, it may use items further up in | 1684 // If the referenced function is a closure, it may use items further up in |
1682 // the nested context, including this one. | 1685 // the nested context, including this one. |
1683 if (ufunc->uf_flags & FC_CLOSURE) | 1686 if (ufunc->uf_flags & FC_CLOSURE) |
5833 | 5836 |
5834 eap->arg = name_end; | 5837 eap->arg = name_end; |
5835 fill_exarg_from_cctx(eap, cctx); | 5838 fill_exarg_from_cctx(eap, cctx); |
5836 | 5839 |
5837 eap->forceit = FALSE; | 5840 eap->forceit = FALSE; |
5841 // We use the special <Lamba>99 name, but it's not really a lambda. | |
5838 lambda_name = vim_strsave(get_lambda_name()); | 5842 lambda_name = vim_strsave(get_lambda_name()); |
5839 if (lambda_name == NULL) | 5843 if (lambda_name == NULL) |
5840 return NULL; | 5844 return NULL; |
5841 ufunc = define_function(eap, lambda_name); | 5845 ufunc = define_function(eap, lambda_name); |
5842 | 5846 |
9974 } | 9978 } |
9975 | 9979 |
9976 switch (ea.cmdidx) | 9980 switch (ea.cmdidx) |
9977 { | 9981 { |
9978 case CMD_def: | 9982 case CMD_def: |
9983 case CMD_function: | |
9979 ea.arg = p; | 9984 ea.arg = p; |
9980 line = compile_nested_function(&ea, &cctx); | 9985 line = compile_nested_function(&ea, &cctx); |
9981 break; | 9986 break; |
9982 | |
9983 case CMD_function: | |
9984 // TODO: should we allow this, e.g. to declare a global | |
9985 // function? | |
9986 emsg(_(e_cannot_use_function_inside_def)); | |
9987 goto erret; | |
9988 | 9987 |
9989 case CMD_return: | 9988 case CMD_return: |
9990 line = compile_return(p, check_return_type, | 9989 line = compile_return(p, check_return_type, |
9991 local_cmdmod.cmod_flags & CMOD_LEGACY, &cctx); | 9990 local_cmdmod.cmod_flags & CMOD_LEGACY, &cctx); |
9992 cctx.ctx_had_return = TRUE; | 9991 cctx.ctx_had_return = TRUE; |
10440 vim_free(isn->isn_arg.ufunc.cuf_name); | 10439 vim_free(isn->isn_arg.ufunc.cuf_name); |
10441 break; | 10440 break; |
10442 | 10441 |
10443 case ISN_FUNCREF: | 10442 case ISN_FUNCREF: |
10444 { | 10443 { |
10445 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) | 10444 if (isn->isn_arg.funcref.fr_func_name == NULL) |
10446 + isn->isn_arg.funcref.fr_func; | 10445 { |
10447 ufunc_T *ufunc = dfunc->df_ufunc; | 10446 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) |
10448 | 10447 + isn->isn_arg.funcref.fr_dfunc_idx; |
10449 if (ufunc != NULL && func_name_refcount(ufunc->uf_name)) | 10448 ufunc_T *ufunc = dfunc->df_ufunc; |
10450 func_ptr_unref(ufunc); | 10449 |
10450 if (ufunc != NULL && func_name_refcount(ufunc->uf_name)) | |
10451 func_ptr_unref(ufunc); | |
10452 } | |
10453 else | |
10454 { | |
10455 char_u *name = isn->isn_arg.funcref.fr_func_name; | |
10456 | |
10457 if (name != NULL) | |
10458 func_unref(name); | |
10459 vim_free(isn->isn_arg.funcref.fr_func_name); | |
10460 } | |
10451 } | 10461 } |
10452 break; | 10462 break; |
10453 | 10463 |
10454 case ISN_DCALL: | 10464 case ISN_DCALL: |
10455 { | 10465 { |