diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-23 17:44:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-23 17:44:08 +0800 |
commit | 1355861b926a05e411ba3d42fa85a2fe238aea8d (patch) | |
tree | 959ba93ec5fb5b927931f448e14a2aaf2e868f5c | |
parent | 3ac952d4e27f4e2454332a730310316fe13fd4a3 (diff) | |
download | rneovim-1355861b926a05e411ba3d42fa85a2fe238aea8d.tar.gz rneovim-1355861b926a05e411ba3d42fa85a2fe238aea8d.tar.bz2 rneovim-1355861b926a05e411ba3d42fa85a2fe238aea8d.zip |
fix(typval): don't treat v:null as truthy (#23281)
-rw-r--r-- | src/nvim/eval/typval.c | 2 | ||||
-rw-r--r-- | test/functional/vimscript/special_vars_spec.lua | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 7c982de61e..357ef6414d 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -4224,7 +4224,7 @@ bool tv2bool(const typval_T *const tv) case VAR_BOOL: return tv->vval.v_bool == kBoolVarTrue; case VAR_SPECIAL: - return tv->vval.v_special == kSpecialVarNull; + return tv->vval.v_special != kSpecialVarNull; case VAR_BLOB: return tv->vval.v_blob != NULL && tv->vval.v_blob->bv_ga.ga_len > 0; case VAR_UNKNOWN: diff --git a/test/functional/vimscript/special_vars_spec.lua b/test/functional/vimscript/special_vars_spec.lua index 14ccbc3827..217f0b2c2b 100644 --- a/test/functional/vimscript/special_vars_spec.lua +++ b/test/functional/vimscript/special_vars_spec.lua @@ -130,6 +130,12 @@ describe('Special values', function() eq("v:false", eval('"" . v:false')) end) + it('work with ?? (falsy operator)', function() + eq(true, eval('v:true ?? 42')) + eq(42, eval('v:false ?? 42')) + eq(42, eval('v:null ?? 42')) + end) + it('work with type()', function() eq(6, funcs.type(true)) eq(6, funcs.type(false)) |