Mercurial > vim
comparison src/evalfunc.c @ 20189:63cc54100ae4 v8.2.0650
patch 8.2.0650: Vim9: script function can be deleted
Commit: https://github.com/vim/vim/commit/4c17ad94ecb0a0fb26d6fface2614bc5172dea18
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Apr 27 22:47:51 2020 +0200
patch 8.2.0650: Vim9: script function can be deleted
Problem: Vim9: script function can be deleted.
Solution: Disallow deleting script function. Delete functions when sourcing
a script again.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 27 Apr 2020 23:00:03 +0200 |
parents | 336483164ca6 |
children | 8d9229c4781a |
comparison
equal
deleted
inserted
replaced
20188:085eb4da46f4 | 20189:63cc54100ae4 |
---|---|
2677 char_u *s; | 2677 char_u *s; |
2678 char_u *name; | 2678 char_u *name; |
2679 int use_string = FALSE; | 2679 int use_string = FALSE; |
2680 partial_T *arg_pt = NULL; | 2680 partial_T *arg_pt = NULL; |
2681 char_u *trans_name = NULL; | 2681 char_u *trans_name = NULL; |
2682 int is_global = FALSE; | |
2682 | 2683 |
2683 if (argvars[0].v_type == VAR_FUNC) | 2684 if (argvars[0].v_type == VAR_FUNC) |
2684 { | 2685 { |
2685 // function(MyFunc, [arg], dict) | 2686 // function(MyFunc, [arg], dict) |
2686 s = argvars[0].vval.v_string; | 2687 s = argvars[0].vval.v_string; |
2700 } | 2701 } |
2701 | 2702 |
2702 if ((use_string && vim_strchr(s, AUTOLOAD_CHAR) == NULL) || is_funcref) | 2703 if ((use_string && vim_strchr(s, AUTOLOAD_CHAR) == NULL) || is_funcref) |
2703 { | 2704 { |
2704 name = s; | 2705 name = s; |
2705 trans_name = trans_function_name(&name, FALSE, | 2706 trans_name = trans_function_name(&name, &is_global, FALSE, |
2706 TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD | TFN_NO_DEREF, NULL, NULL); | 2707 TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD | TFN_NO_DEREF, NULL, NULL); |
2707 if (*name != NUL) | 2708 if (*name != NUL) |
2708 s = NULL; | 2709 s = NULL; |
2709 else if (trans_name != NULL | |
2710 && ASCII_ISUPPER(*s) | |
2711 && current_sctx.sc_version == SCRIPT_VERSION_VIM9 | |
2712 && find_func(trans_name, NULL) == NULL) | |
2713 { | |
2714 // With Vim9 script "MyFunc" can be script-local to the current | |
2715 // script or global. The script-local name is not found, assume | |
2716 // global. | |
2717 vim_free(trans_name); | |
2718 trans_name = vim_strsave(s); | |
2719 } | |
2720 } | 2710 } |
2721 | 2711 |
2722 if (s == NULL || *s == NUL || (use_string && VIM_ISDIGIT(*s)) | 2712 if (s == NULL || *s == NUL || (use_string && VIM_ISDIGIT(*s)) |
2723 || (is_funcref && trans_name == NULL)) | 2713 || (is_funcref && trans_name == NULL)) |
2724 semsg(_(e_invarg2), use_string ? tv_get_string(&argvars[0]) : s); | 2714 semsg(_(e_invarg2), use_string ? tv_get_string(&argvars[0]) : s); |
2725 // Don't check an autoload name for existence here. | 2715 // Don't check an autoload name for existence here. |
2726 else if (trans_name != NULL && (is_funcref | 2716 else if (trans_name != NULL && (is_funcref |
2727 ? find_func(trans_name, NULL) == NULL | 2717 ? find_func(trans_name, is_global, NULL) == NULL |
2728 : !translated_function_exists(trans_name))) | 2718 : !translated_function_exists(trans_name, is_global))) |
2729 semsg(_("E700: Unknown function: %s"), s); | 2719 semsg(_("E700: Unknown function: %s"), s); |
2730 else | 2720 else |
2731 { | 2721 { |
2732 int dict_idx = 0; | 2722 int dict_idx = 0; |
2733 int arg_idx = 0; | 2723 int arg_idx = 0; |
2860 func_ptr_ref(pt->pt_func); | 2850 func_ptr_ref(pt->pt_func); |
2861 vim_free(name); | 2851 vim_free(name); |
2862 } | 2852 } |
2863 else if (is_funcref) | 2853 else if (is_funcref) |
2864 { | 2854 { |
2865 pt->pt_func = find_func(trans_name, NULL); | 2855 pt->pt_func = find_func(trans_name, is_global, NULL); |
2866 func_ptr_ref(pt->pt_func); | 2856 func_ptr_ref(pt->pt_func); |
2867 vim_free(name); | 2857 vim_free(name); |
2868 } | 2858 } |
2869 else | 2859 else |
2870 { | 2860 { |