Mercurial > vim
comparison src/eval.c @ 21725:741c1d58d50f v8.2.1412
patch 8.2.1412: Vim: not operator does not result in boolean
Commit: https://github.com/vim/vim/commit/6e4cfffe809a894ea831fc8011527714481d2857
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 9 22:17:55 2020 +0200
patch 8.2.1412: Vim: not operator does not result in boolean
Problem: Vim: not operator does not result in boolean.
Solution: Make type depend on operator. (issue 6678) Fix using "false" and
"true" in Vim9 script.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 09 Aug 2020 22:30:03 +0200 |
parents | f41c646cb8b9 |
children | 1bb5adfe5966 |
comparison
equal
deleted
inserted
replaced
21724:360d215e34a0 | 21725:741c1d58d50f |
---|---|
3220 // get the value of "true", "false" or a variable | 3220 // get the value of "true", "false" or a variable |
3221 if (len == 4 && in_vim9script() && STRNCMP(s, "true", 4) == 0) | 3221 if (len == 4 && in_vim9script() && STRNCMP(s, "true", 4) == 0) |
3222 { | 3222 { |
3223 rettv->v_type = VAR_BOOL; | 3223 rettv->v_type = VAR_BOOL; |
3224 rettv->vval.v_number = VVAL_TRUE; | 3224 rettv->vval.v_number = VVAL_TRUE; |
3225 ret = OK; | |
3225 } | 3226 } |
3226 else if (len == 5 && in_vim9script() | 3227 else if (len == 5 && in_vim9script() |
3227 && STRNCMP(s, "false", 4) == 0) | 3228 && STRNCMP(s, "false", 4) == 0) |
3228 { | 3229 { |
3229 rettv->v_type = VAR_BOOL; | 3230 rettv->v_type = VAR_BOOL; |
3230 rettv->vval.v_number = VVAL_FALSE; | 3231 rettv->vval.v_number = VVAL_FALSE; |
3232 ret = OK; | |
3231 } | 3233 } |
3232 else | 3234 else |
3233 ret = eval_variable(s, len, rettv, NULL, TRUE, FALSE); | 3235 ret = eval_variable(s, len, rettv, NULL, TRUE, FALSE); |
3234 } | 3236 } |
3235 else | 3237 else |
3269 { | 3271 { |
3270 char_u *end_leader = *end_leaderp; | 3272 char_u *end_leader = *end_leaderp; |
3271 int ret = OK; | 3273 int ret = OK; |
3272 int error = FALSE; | 3274 int error = FALSE; |
3273 varnumber_T val = 0; | 3275 varnumber_T val = 0; |
3276 vartype_T type = rettv->v_type; | |
3274 #ifdef FEAT_FLOAT | 3277 #ifdef FEAT_FLOAT |
3275 float_T f = 0.0; | 3278 float_T f = 0.0; |
3276 | 3279 |
3277 if (rettv->v_type == VAR_FLOAT) | 3280 if (rettv->v_type == VAR_FLOAT) |
3278 f = rettv->vval.v_float; | 3281 f = rettv->vval.v_float; |
3299 #ifdef FEAT_FLOAT | 3302 #ifdef FEAT_FLOAT |
3300 if (rettv->v_type == VAR_FLOAT) | 3303 if (rettv->v_type == VAR_FLOAT) |
3301 f = !f; | 3304 f = !f; |
3302 else | 3305 else |
3303 #endif | 3306 #endif |
3307 { | |
3304 val = !val; | 3308 val = !val; |
3309 type = VAR_BOOL; | |
3310 } | |
3305 } | 3311 } |
3306 else if (*end_leader == '-') | 3312 else if (*end_leader == '-') |
3307 { | 3313 { |
3308 #ifdef FEAT_FLOAT | 3314 #ifdef FEAT_FLOAT |
3309 if (rettv->v_type == VAR_FLOAT) | 3315 if (rettv->v_type == VAR_FLOAT) |
3310 f = -f; | 3316 f = -f; |
3311 else | 3317 else |
3312 #endif | 3318 #endif |
3319 { | |
3313 val = -val; | 3320 val = -val; |
3321 type = VAR_NUMBER; | |
3322 } | |
3314 } | 3323 } |
3315 } | 3324 } |
3316 #ifdef FEAT_FLOAT | 3325 #ifdef FEAT_FLOAT |
3317 if (rettv->v_type == VAR_FLOAT) | 3326 if (rettv->v_type == VAR_FLOAT) |
3318 { | 3327 { |
3321 } | 3330 } |
3322 else | 3331 else |
3323 #endif | 3332 #endif |
3324 { | 3333 { |
3325 clear_tv(rettv); | 3334 clear_tv(rettv); |
3326 rettv->v_type = VAR_NUMBER; | 3335 if (in_vim9script()) |
3336 rettv->v_type = type; | |
3337 else | |
3338 rettv->v_type = VAR_NUMBER; | |
3327 rettv->vval.v_number = val; | 3339 rettv->vval.v_number = val; |
3328 } | 3340 } |
3329 } | 3341 } |
3330 *end_leaderp = end_leader; | 3342 *end_leaderp = end_leader; |
3331 return ret; | 3343 return ret; |