Mercurial > vim
changeset 28011:d10d5cc8e657 v8.2.4530
patch 8.2.4530: making comparison with null work changes legacy behavior
Commit: https://github.com/vim/vim/commit/f3507a517c38bee5498736607ead64c8ae6b5941
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Mar 9 11:56:21 2022 +0000
patch 8.2.4530: making comparison with null work changes legacy behavior
Problem: Making comparison with null work changes legacy behavior.
Solution: Only use the better comparison in Vim9 script. (closes https://github.com/vim/vim/issues/9910)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 09 Mar 2022 13:00:03 +0100 |
parents | c968191a8557 |
children | f93f7e634c40 |
files | src/testdir/test_expr.vim src/typval.c src/version.c |
diffstat | 3 files changed, 38 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/test_expr.vim +++ b/src/testdir/test_expr.vim @@ -181,6 +181,38 @@ func Test_loop_over_null_list() call v9.CheckScriptFailure(lines, 'E121: Undefined variable: null_list') endfunc +func Test_compare_with_null() + let s:value = v:null + call assert_true(s:value == v:null) + let s:value = v:true + call assert_false(s:value == v:null) + let s:value = v:none + call assert_false(s:value == v:null) + let s:value = 0 + call assert_true(s:value == v:null) + if has('float') + let s:value = 0.0 + call assert_true(s:value == v:null) + endif + let s:value = '' + call assert_false(s:value == v:null) + let s:value = 0z + call assert_false(s:value == v:null) + let s:value = [] + call assert_false(s:value == v:null) + let s:value = {} + call assert_false(s:value == v:null) + let s:value = function('len') + call assert_false(s:value == v:null) + if has('job') + let s:value = test_null_job() + call assert_true(s:value == v:null) + let s:value = test_null_channel() + call assert_true(s:value == v:null) + endif + unlet s:value +endfunc + func Test_setreg_null_list() let lines =<< trim END call setreg('x', test_null_list())
--- a/src/typval.c +++ b/src/typval.c @@ -1381,7 +1381,7 @@ typval_compare_list( } /* - * Compare v:null/v:none with another type. Return TRUE if the value is NULL. + * Compare v:null with another type. Return TRUE if the value is NULL. */ int typval_compare_null(typval_T *tv1, typval_T *tv2) @@ -1417,6 +1417,9 @@ typval_compare_null(typval_T *tv1, typva default: break; } } + if (!in_vim9script()) + return FALSE; // backwards compatible + semsg(_(e_cannot_compare_str_with_str), vartype_name(tv1->v_type), vartype_name(tv2->v_type)); return MAYBE;