Mercurial > vim
comparison src/vim9type.c @ 27517:f00a7a2bee21 v8.2.4286
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Commit: https://github.com/vim/vim/commit/381692b6f1c2ec9b73a139500286ddc9347a1c01
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 2 20:01:27 2022 +0000
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Problem: Vim9: strict type checking after copy() and deepcopy().
Solution: Allow type to change after making a copy. (closes https://github.com/vim/vim/issues/9644)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 02 Feb 2022 21:15:03 +0100 |
parents | 4cea92e99a5a |
children | 7898c7847293 |
comparison
equal
deleted
inserted
replaced
27516:fdcbdd530e4c | 27517:f00a7a2bee21 |
---|---|
98 free_type(type->tt_args[i]); | 98 free_type(type->tt_args[i]); |
99 vim_free(type->tt_args); | 99 vim_free(type->tt_args); |
100 } | 100 } |
101 free_type(type->tt_member); | 101 free_type(type->tt_member); |
102 vim_free(type); | 102 vim_free(type); |
103 } | |
104 | |
105 /* | |
106 * Return TRUE if "type" is to be recursed into for setting the type. | |
107 */ | |
108 static int | |
109 set_tv_type_recurse(type_T *type) | |
110 { | |
111 return type->tt_member != NULL | |
112 && (type->tt_member->tt_type == VAR_DICT | |
113 || type->tt_member->tt_type == VAR_LIST) | |
114 && type->tt_member->tt_member != NULL | |
115 && type->tt_member->tt_member != &t_any | |
116 && type->tt_member->tt_member != &t_unknown; | |
117 } | |
118 | |
119 /* | |
120 * Set the type of "tv" to "type" if it is a list or dict. | |
121 */ | |
122 void | |
123 set_tv_type(typval_T *tv, type_T *type) | |
124 { | |
125 if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL) | |
126 { | |
127 dict_T *d = tv->vval.v_dict; | |
128 | |
129 if (d->dv_type != type) | |
130 { | |
131 free_type(d->dv_type); | |
132 d->dv_type = alloc_type(type); | |
133 if (set_tv_type_recurse(type)) | |
134 { | |
135 int todo = (int)d->dv_hashtab.ht_used; | |
136 hashitem_T *hi; | |
137 dictitem_T *di; | |
138 | |
139 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) | |
140 { | |
141 if (!HASHITEM_EMPTY(hi)) | |
142 { | |
143 --todo; | |
144 di = HI2DI(hi); | |
145 set_tv_type(&di->di_tv, type->tt_member); | |
146 } | |
147 } | |
148 } | |
149 } | |
150 } | |
151 else if (tv->v_type == VAR_LIST && tv->vval.v_list != NULL) | |
152 { | |
153 list_T *l = tv->vval.v_list; | |
154 | |
155 if (l->lv_type != type) | |
156 { | |
157 free_type(l->lv_type); | |
158 l->lv_type = alloc_type(type); | |
159 if (l->lv_first != &range_list_item && set_tv_type_recurse(type)) | |
160 { | |
161 listitem_T *li; | |
162 | |
163 FOR_ALL_LIST_ITEMS(l, li) | |
164 set_tv_type(&li->li_tv, type->tt_member); | |
165 } | |
166 } | |
167 } | |
103 } | 168 } |
104 | 169 |
105 type_T * | 170 type_T * |
106 get_list_type(type_T *member_type, garray_T *type_gap) | 171 get_list_type(type_T *member_type, garray_T *type_gap) |
107 { | 172 { |