Mercurial > vim
comparison src/evalvars.c @ 22202:7899b4e2880c v8.2.1650
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Commit: https://github.com/vim/vim/commit/c1ec0422e43720d2e96627605532ee9806c0789f
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Sep 9 22:27:58 2020 +0200
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Problem: Vim9: result of && and || expression cannot be assigned to a bool
at the script level.
Solution: Add the VAR_BOOL_OK flag. Convert to bool when needed.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 09 Sep 2020 22:30:04 +0200 |
parents | ee967cdcf749 |
children | 88927d5f275d |
comparison
equal
deleted
inserted
replaced
22201:11ef4208bffe | 22202:7899b4e2880c |
---|---|
776 else | 776 else |
777 { | 777 { |
778 evalarg_T evalarg; | 778 evalarg_T evalarg; |
779 int len = 1; | 779 int len = 1; |
780 | 780 |
781 rettv.v_type = VAR_UNKNOWN; | 781 CLEAR_FIELD(rettv); |
782 i = FAIL; | 782 i = FAIL; |
783 if (has_assign || concat) | 783 if (has_assign || concat) |
784 { | 784 { |
785 op[0] = '='; | 785 op[0] = '='; |
786 op[1] = NUL; | 786 op[1] = NUL; |
2933 */ | 2933 */ |
2934 void | 2934 void |
2935 set_var_const( | 2935 set_var_const( |
2936 char_u *name, | 2936 char_u *name, |
2937 type_T *type, | 2937 type_T *type, |
2938 typval_T *tv, | 2938 typval_T *tv_arg, |
2939 int copy, // make copy of value in "tv" | 2939 int copy, // make copy of value in "tv" |
2940 int flags) // LET_IS_CONST and/or LET_NO_COMMAND | 2940 int flags) // LET_IS_CONST and/or LET_NO_COMMAND |
2941 { | 2941 { |
2942 typval_T *tv = tv_arg; | |
2943 typval_T bool_tv; | |
2942 dictitem_T *di; | 2944 dictitem_T *di; |
2943 char_u *varname; | 2945 char_u *varname; |
2944 hashtab_T *ht; | 2946 hashtab_T *ht; |
2945 int is_script_local; | 2947 int is_script_local; |
2946 | 2948 |
2968 di = find_var_in_scoped_ht(name, TRUE); | 2970 di = find_var_in_scoped_ht(name, TRUE); |
2969 | 2971 |
2970 if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL) | 2972 if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL) |
2971 && var_wrong_func_name(name, di == NULL)) | 2973 && var_wrong_func_name(name, di == NULL)) |
2972 return; | 2974 return; |
2975 | |
2976 if (need_convert_to_bool(type, tv)) | |
2977 { | |
2978 // Destination is a bool and the value is not, but it can be converted. | |
2979 CLEAR_FIELD(bool_tv); | |
2980 bool_tv.v_type = VAR_BOOL; | |
2981 bool_tv.vval.v_number = tv2bool(tv) ? VVAL_TRUE : VVAL_FALSE; | |
2982 tv = &bool_tv; | |
2983 } | |
2973 | 2984 |
2974 if (di != NULL) | 2985 if (di != NULL) |
2975 { | 2986 { |
2976 if ((di->di_flags & DI_FLAGS_RELOAD) == 0) | 2987 if ((di->di_flags & DI_FLAGS_RELOAD) == 0) |
2977 { | 2988 { |
2987 { | 2998 { |
2988 semsg(_(e_redefining_script_item_str), name); | 2999 semsg(_(e_redefining_script_item_str), name); |
2989 return; | 3000 return; |
2990 } | 3001 } |
2991 | 3002 |
2992 // check the type | 3003 // check the type and adjust to bool if needed |
2993 if (check_script_var_type(&di->di_tv, tv, name) == FAIL) | 3004 if (check_script_var_type(&di->di_tv, tv, name) == FAIL) |
2994 return; | 3005 return; |
2995 } | 3006 } |
2996 | 3007 |
2997 if (var_check_ro(di->di_flags, name, FALSE) | 3008 if (var_check_ro(di->di_flags, name, FALSE) |