Mercurial > vim
comparison src/vim9script.c @ 28345:fabe722b24e9 v8.2.4698
patch 8.2.4698: Vim9: script variable has no flag that it was set
Commit: https://github.com/vim/vim/commit/aa7d0c233532fb9d8c2876ea8e978a82b12c377f
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Apr 5 21:40:38 2022 +0100
patch 8.2.4698: Vim9: script variable has no flag that it was set
Problem: Vim9: script variable has no flag that it was set.
Solution: Add a flag that it was set, to avoid giving it a value when used.
(closes #10088)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 05 Apr 2022 22:45:03 +0200 |
parents | b418e073b42f |
children | 4dcccb2673fe |
comparison
equal
deleted
inserted
replaced
28344:10a99c04ba1d | 28345:fabe722b24e9 |
---|---|
332 | 332 |
333 for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx) | 333 for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx) |
334 { | 334 { |
335 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx; | 335 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx; |
336 | 336 |
337 if (sv->sv_type_allocated) | 337 if (sv->sv_flags & SVFLAG_TYPE_ALLOCATED) |
338 free_type(sv->sv_type); | 338 free_type(sv->sv_type); |
339 } | 339 } |
340 ga_clear(&si->sn_var_vals); | 340 ga_clear(&si->sn_var_vals); |
341 | 341 |
342 // existing commands using script variable indexes are no longer valid | 342 // existing commands using script variable indexes are no longer valid |
719 idx = get_script_item_idx(sid, name, 0, cctx, cstack); | 719 idx = get_script_item_idx(sid, name, 0, cctx, cstack); |
720 if (idx >= 0) | 720 if (idx >= 0) |
721 { | 721 { |
722 sv = ((svar_T *)script->sn_var_vals.ga_data) + idx; | 722 sv = ((svar_T *)script->sn_var_vals.ga_data) + idx; |
723 *ufunc = NULL; | 723 *ufunc = NULL; |
724 if (!sv->sv_export) | 724 if ((sv->sv_flags & SVFLAG_EXPORTED) == 0) |
725 { | 725 { |
726 if (verbose) | 726 if (verbose) |
727 semsg(_(e_item_not_exported_in_script_str), name); | 727 semsg(_(e_item_not_exported_in_script_str), name); |
728 return -1; | 728 return -1; |
729 } | 729 } |
869 /* | 869 /* |
870 * Vim9 part of adding a script variable: add it to sn_all_vars (lookup by name | 870 * Vim9 part of adding a script variable: add it to sn_all_vars (lookup by name |
871 * with a hashtable) and sn_var_vals (lookup by index). | 871 * with a hashtable) and sn_var_vals (lookup by index). |
872 * When "create" is TRUE this is a new variable, otherwise find and update an | 872 * When "create" is TRUE this is a new variable, otherwise find and update an |
873 * existing variable. | 873 * existing variable. |
874 * "flags" can have ASSIGN_FINAL or ASSIGN_CONST. | 874 * "flags" can have ASSIGN_FINAL, ASSIGN_CONST or ASSIGN_INIT. |
875 * When "*type" is NULL use "tv" for the type and update "*type". If | 875 * When "*type" is NULL use "tv" for the type and update "*type". If |
876 * "do_member" is TRUE also use the member type, otherwise use "any". | 876 * "do_member" is TRUE also use the member type, otherwise use "any". |
877 */ | 877 */ |
878 void | 878 void |
879 update_vim9_script_var( | 879 update_vim9_script_var( |
936 return; | 936 return; |
937 | 937 |
938 sv->sv_tv = &di->di_tv; | 938 sv->sv_tv = &di->di_tv; |
939 sv->sv_const = (flags & ASSIGN_FINAL) ? ASSIGN_FINAL | 939 sv->sv_const = (flags & ASSIGN_FINAL) ? ASSIGN_FINAL |
940 : (flags & ASSIGN_CONST) ? ASSIGN_CONST : 0; | 940 : (flags & ASSIGN_CONST) ? ASSIGN_CONST : 0; |
941 sv->sv_export = is_export; | 941 sv->sv_flags = is_export ? SVFLAG_EXPORTED : 0; |
942 if ((flags & ASSIGN_INIT) == 0) | |
943 sv->sv_flags |= SVFLAG_ASSIGNED; | |
942 newsav->sav_var_vals_idx = si->sn_var_vals.ga_len; | 944 newsav->sav_var_vals_idx = si->sn_var_vals.ga_len; |
943 ++si->sn_var_vals.ga_len; | 945 ++si->sn_var_vals.ga_len; |
944 STRCPY(&newsav->sav_key, name); | 946 STRCPY(&newsav->sav_key, name); |
945 sv->sv_name = newsav->sav_key; | 947 sv->sv_name = newsav->sav_key; |
946 newsav->sav_di = di; | 948 newsav->sav_di = di; |
968 && tv->vval.v_blob == NULL) | 970 && tv->vval.v_blob == NULL) |
969 { | 971 { |
970 // "var b: blob = null_blob" has a different type. | 972 // "var b: blob = null_blob" has a different type. |
971 *type = &t_blob_null; | 973 *type = &t_blob_null; |
972 } | 974 } |
973 if (sv->sv_type_allocated) | 975 if (sv->sv_flags & SVFLAG_TYPE_ALLOCATED) |
974 free_type(sv->sv_type); | 976 free_type(sv->sv_type); |
975 if (*type != NULL && ((*type)->tt_type == VAR_FUNC | 977 if (*type != NULL && ((*type)->tt_type == VAR_FUNC |
976 || (*type)->tt_type == VAR_PARTIAL)) | 978 || (*type)->tt_type == VAR_PARTIAL)) |
977 { | 979 { |
978 // The type probably uses uf_type_list, which is cleared when the | 980 // The type probably uses uf_type_list, which is cleared when the |
979 // function is freed, but the script variable may keep the type. | 981 // function is freed, but the script variable may keep the type. |
980 // Make a copy to avoid using freed memory. | 982 // Make a copy to avoid using freed memory. |
981 sv->sv_type = alloc_type(*type); | 983 sv->sv_type = alloc_type(*type); |
982 sv->sv_type_allocated = TRUE; | 984 sv->sv_flags |= SVFLAG_TYPE_ALLOCATED; |
983 } | 985 } |
984 else | 986 else |
985 { | 987 { |
986 sv->sv_type = *type; | 988 sv->sv_type = *type; |
987 sv->sv_type_allocated = FALSE; | 989 sv->sv_flags &= ~SVFLAG_TYPE_ALLOCATED; |
988 } | 990 } |
989 } | 991 } |
990 | 992 |
991 // let ex_export() know the export worked. | 993 // let ex_export() know the export worked. |
992 is_export = FALSE; | 994 is_export = FALSE; |