comparison src/eval.c @ 21733:1bb5adfe5966 v8.2.1416

patch 8.2.1416: Vim9: boolean evaluation does not work as intended Commit: https://github.com/vim/vim/commit/3e06a1e2a8c0854c881574f33363e00264db1f1d Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 10 21:57:54 2020 +0200 patch 8.2.1416: Vim9: boolean evaluation does not work as intended Problem: Vim9: boolean evaluation does not work as intended. Solution: Use tv2bool() in Vim9 script. (closes https://github.com/vim/vim/issues/6681)
author Bram Moolenaar <Bram@vim.org>
date Mon, 10 Aug 2020 22:00:05 +0200
parents 741c1d58d50f
children fcf978444298
comparison
equal deleted inserted replaced
21732:f0845166f35b 21733:1bb5adfe5966
190 else 190 else
191 { 191 {
192 *error = FALSE; 192 *error = FALSE;
193 if (!skip) 193 if (!skip)
194 { 194 {
195 retval = (tv_get_number_chk(&tv, error) != 0); 195 if (in_vim9script())
196 retval = tv2bool(&tv);
197 else
198 retval = (tv_get_number_chk(&tv, error) != 0);
196 clear_tv(&tv); 199 clear_tv(&tv);
197 } 200 }
198 } 201 }
199 if (skip) 202 if (skip)
200 --emsg_skip; 203 --emsg_skip;
3096 case '9': 3099 case '9':
3097 case '.': ret = eval_number(arg, rettv, evaluate, want_string); 3100 case '.': ret = eval_number(arg, rettv, evaluate, want_string);
3098 3101
3099 // Apply prefixed "-" and "+" now. Matters especially when 3102 // Apply prefixed "-" and "+" now. Matters especially when
3100 // "->" follows. 3103 // "->" follows.
3101 if (ret == OK && evaluate && end_leader > start_leader) 3104 if (ret == OK && evaluate && end_leader > start_leader
3105 && rettv->v_type != VAR_BLOB)
3102 ret = eval7_leader(rettv, TRUE, start_leader, &end_leader); 3106 ret = eval7_leader(rettv, TRUE, start_leader, &end_leader);
3103 break; 3107 break;
3104 3108
3105 /* 3109 /*
3106 * String constant: "string". 3110 * String constant: "string".
3279 3283
3280 if (rettv->v_type == VAR_FLOAT) 3284 if (rettv->v_type == VAR_FLOAT)
3281 f = rettv->vval.v_float; 3285 f = rettv->vval.v_float;
3282 else 3286 else
3283 #endif 3287 #endif
3284 val = tv_get_number_chk(rettv, &error); 3288 if (in_vim9script() && end_leader[-1] == '!')
3289 val = tv2bool(rettv);
3290 else
3291 val = tv_get_number_chk(rettv, &error);
3285 if (error) 3292 if (error)
3286 { 3293 {
3287 clear_tv(rettv); 3294 clear_tv(rettv);
3288 ret = FAIL; 3295 ret = FAIL;
3289 } 3296 }