comparison src/vim9type.c @ 22494:4c21f7f6f9e3 v8.2.1795

patch 8.2.1795: Vim9: operators && and || have a confusing result Commit: https://github.com/vim/vim/commit/2bb2658bef9fb25b320f87147261b7154494a86f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 3 22:52:39 2020 +0200 patch 8.2.1795: Vim9: operators && and || have a confusing result Problem: Vim9: operators && and || have a confusing result. Solution: Make the result a boolean.
author Bram Moolenaar <Bram@vim.org>
date Sat, 03 Oct 2020 23:00:04 +0200
parents 0e03ef68e738
children af26fadf333d
comparison
equal deleted inserted replaced
22493:51353715e9a1 22494:4c21f7f6f9e3
358 */ 358 */
359 int 359 int
360 need_convert_to_bool(type_T *type, typval_T *tv) 360 need_convert_to_bool(type_T *type, typval_T *tv)
361 { 361 {
362 return type != NULL && type == &t_bool && tv->v_type != VAR_BOOL 362 return type != NULL && type == &t_bool && tv->v_type != VAR_BOOL
363 && ((tv->v_lock & VAR_BOOL_OK) 363 && (tv->v_type == VAR_NUMBER
364 || (tv->v_type == VAR_NUMBER 364 && (tv->vval.v_number == 0 || tv->vval.v_number == 1));
365 && (tv->vval.v_number == 0 || tv->vval.v_number == 1))); 365 }
366 } 366
367 367 /*
368 /* 368 * Get a type_T for a typval_T.
369 * Get a type_T for a typval_T and handle VAR_BOOL_OK.
370 * "type_list" is used to temporarily create types in. 369 * "type_list" is used to temporarily create types in.
371 */ 370 */
372 type_T * 371 type_T *
373 typval2type(typval_T *tv, garray_T *type_gap) 372 typval2type(typval_T *tv, garray_T *type_gap)
374 { 373 {
375 type_T *type = typval2type_int(tv, type_gap); 374 type_T *type = typval2type_int(tv, type_gap);
376 375
377 if (type != NULL && type != &t_bool 376 if (type != NULL && type != &t_bool
378 && ((tv->v_type == VAR_NUMBER 377 && (tv->v_type == VAR_NUMBER
379 && (tv->vval.v_number == 0 || tv->vval.v_number == 1)) 378 && (tv->vval.v_number == 0 || tv->vval.v_number == 1)))
380 || (tv->v_lock & VAR_BOOL_OK)))
381 { 379 {
382 type_T *newtype = get_type_ptr(type_gap); 380 type_T *newtype = get_type_ptr(type_gap);
383 381
384 // Number 0 and 1 and expression with "&&" or "||" can also be used 382 // Number 0 and 1 and expression with "&&" or "||" can also be used
385 // for bool. 383 // for bool.