comparison src/vim9type.c @ 22190:da851f3b6a0b v8.2.1644

patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level Commit: https://github.com/vim/vim/commit/ba7c0d7b4ce03336b4aebe1959c1a8342fa6dbd4 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 9 18:54:42 2020 +0200 patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level Problem: Vim9: cannot assign 1 and 0 to bool at script level. Solution: Add the TTFLAG_BOOL_OK flag to the type. Fix name of test function.
author Bram Moolenaar <Bram@vim.org>
date Wed, 09 Sep 2020 19:00:04 +0200
parents 2463b3d89ce2
children 7899b4e2880c
comparison
equal deleted inserted replaced
22189:c0aafebff6d9 22190:da851f3b6a0b
200 * "type_list" is used to temporarily create types in. 200 * "type_list" is used to temporarily create types in.
201 */ 201 */
202 type_T * 202 type_T *
203 typval2type(typval_T *tv, garray_T *type_gap) 203 typval2type(typval_T *tv, garray_T *type_gap)
204 { 204 {
205 type_T *actual; 205 type_T *type;
206 type_T *member_type; 206 type_T *member_type;
207 207
208 if (tv->v_type == VAR_NUMBER) 208 if (tv->v_type == VAR_NUMBER)
209 {
210 if (tv->vval.v_number == 0 || tv->vval.v_number == 1)
211 {
212 // number 0 and 1 can also be used for bool
213 type = alloc_type(type_gap);
214 if (type == NULL)
215 return NULL;
216 type->tt_type = VAR_NUMBER;
217 type->tt_flags = TTFLAG_BOOL_OK;
218 return type;
219 }
209 return &t_number; 220 return &t_number;
221 }
210 if (tv->v_type == VAR_BOOL) 222 if (tv->v_type == VAR_BOOL)
211 return &t_bool; // not used 223 return &t_bool; // not used
212 if (tv->v_type == VAR_STRING) 224 if (tv->v_type == VAR_STRING)
213 return &t_string; 225 return &t_string;
214 226
274 if (ufunc->uf_func_type != NULL) 286 if (ufunc->uf_func_type != NULL)
275 return ufunc->uf_func_type; 287 return ufunc->uf_func_type;
276 } 288 }
277 } 289 }
278 290
279 actual = alloc_type(type_gap); 291 type = alloc_type(type_gap);
280 if (actual == NULL) 292 if (type == NULL)
281 return NULL; 293 return NULL;
282 actual->tt_type = tv->v_type; 294 type->tt_type = tv->v_type;
283 actual->tt_member = &t_any; 295 type->tt_member = &t_any;
284 296
285 return actual; 297 return type;
286 } 298 }
287 299
288 /* 300 /*
289 * Get a type_T for a typval_T, used for v: variables. 301 * Get a type_T for a typval_T, used for v: variables.
290 * "type_list" is used to temporarily create types in. 302 * "type_list" is used to temporarily create types in.