Mercurial > vim
changeset 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 | 360d215e34a0 |
children | c4d9bcbaf320 |
files | src/eval.c src/testdir/test_vim9_expr.vim src/version.c |
diffstat | 3 files changed, 33 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -3222,12 +3222,14 @@ eval7( { rettv->v_type = VAR_BOOL; rettv->vval.v_number = VVAL_TRUE; + ret = OK; } else if (len == 5 && in_vim9script() && STRNCMP(s, "false", 4) == 0) { rettv->v_type = VAR_BOOL; rettv->vval.v_number = VVAL_FALSE; + ret = OK; } else ret = eval_variable(s, len, rettv, NULL, TRUE, FALSE); @@ -3271,6 +3273,7 @@ eval7_leader( int ret = OK; int error = FALSE; varnumber_T val = 0; + vartype_T type = rettv->v_type; #ifdef FEAT_FLOAT float_T f = 0.0; @@ -3301,7 +3304,10 @@ eval7_leader( f = !f; else #endif + { val = !val; + type = VAR_BOOL; + } } else if (*end_leader == '-') { @@ -3310,7 +3316,10 @@ eval7_leader( f = -f; else #endif + { val = -val; + type = VAR_NUMBER; + } } } #ifdef FEAT_FLOAT @@ -3323,7 +3332,10 @@ eval7_leader( #endif { clear_tv(rettv); - rettv->v_type = VAR_NUMBER; + if (in_vim9script()) + rettv->v_type = type; + else + rettv->v_type = VAR_NUMBER; rettv->vval.v_number = val; } }
--- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -1313,6 +1313,16 @@ def Test_expr7_special() assert_equal(g:special_false, false) assert_equal(g:special_true, v:true) assert_equal(g:special_false, v:false) + + assert_equal(true, !false) + assert_equal(false, !true) + assert_equal(true, !0) + assert_equal(false, !1) + assert_equal(false, !!false) + assert_equal(true, !!true) + assert_equal(false, !!0) + assert_equal(true, !!1) + assert_equal(g:special_null, v:null) assert_equal(g:special_none, v:none) @@ -1332,6 +1342,14 @@ def Test_expr7_special_vim9script() assert_equal(true, t) assert_equal(v:false, false) assert_equal(false, f) + assert_equal(true, !false) + assert_equal(false, !true) + assert_equal(true, !0) + assert_equal(false, !1) + assert_equal(false, !!false) + assert_equal(true, !!true) + assert_equal(false, !!0) + assert_equal(true, !!1) END CheckScriptSuccess(lines) enddef