To: vim_dev@googlegroups.com Subject: Patch 8.2.4576 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4576 Problem: Vim9: error for comparing with null can be annoying. Solution: Allow comparing anything with null. (closes #9948) Files: src/vim9instr.c, src/typval.c, src/testdir/test_vim9_expr.vim *** ../vim-8.2.4575/src/vim9instr.c 2022-03-15 19:29:26.546954678 +0000 --- src/vim9instr.c 2022-03-15 20:20:46.693330758 +0000 *************** *** 397,416 **** vartype_name(vartype1), vartype_name(vartype2)); return ISN_DROP; } ! switch (vartype1 == VAR_SPECIAL ? vartype2 : vartype1) ! { ! case VAR_BLOB: break; ! case VAR_CHANNEL: break; ! case VAR_DICT: break; ! case VAR_FUNC: break; ! case VAR_JOB: break; ! case VAR_LIST: break; ! case VAR_PARTIAL: break; ! case VAR_STRING: break; ! default: semsg(_(e_cannot_compare_str_with_str), ! vartype_name(vartype1), vartype_name(vartype2)); ! return ISN_DROP; ! } isntype = ISN_COMPARENULL; } --- 397,404 ---- vartype_name(vartype1), vartype_name(vartype2)); return ISN_DROP; } ! // although comparing null with number, float or bool is not useful, we ! // allow it isntype = ISN_COMPARENULL; } *** ../vim-8.2.4575/src/typval.c 2022-03-10 12:20:48.538552976 +0000 --- src/typval.c 2022-03-15 20:21:05.533354481 +0000 *************** *** 1417,1428 **** 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; } /* --- 1417,1425 ---- default: break; } } ! // although comparing null with number, float or bool is not very usefule ! // we won't give an error ! return FALSE; } /* *** ../vim-8.2.4575/src/testdir/test_vim9_expr.vim 2022-03-10 20:01:47.119865247 +0000 --- src/testdir/test_vim9_expr.vim 2022-03-15 20:12:30.830004374 +0000 *************** *** 716,721 **** --- 716,750 ---- g:null_dict = test_null_dict() g:not_null_list = [] var lines =<< trim END + assert_false(true == null) + assert_false(false == null) + assert_false(null == true) + assert_false(null == false) + assert_true(true != null) + assert_true(false != null) + assert_true(null != true) + assert_true(null != false) + + assert_false(123 == null) + assert_false(0 == null) + assert_false(null == 123) + assert_false(null == 0) + assert_true(123 != null) + assert_true(0 != null) + assert_true(null != 123) + assert_true(null != 0) + + if has('float') + assert_false(12.3 == null) + assert_false(0.0 == null) + assert_false(null == 12.3) + assert_false(null == 0.0) + assert_true(12.3 != null) + assert_true(0.0 != null) + assert_true(null != 12.3) + assert_true(null != 0.0) + endif + assert_true(test_null_blob() == v:null) assert_true(null_blob == null) assert_true(v:null == test_null_blob()) *************** *** 818,833 **** assert_equal(null_function, d.f) END v9.CheckDefAndScriptSuccess(lines) - - v9.CheckDefAndScriptFailure(['echo 123 == v:null'], 'E1072: Cannot compare number with special') - v9.CheckDefAndScriptFailure(['echo v:null == 123'], 'E1072: Cannot compare special with number') - v9.CheckDefAndScriptFailure(['echo 123 != v:null'], 'E1072: Cannot compare number with special') - v9.CheckDefAndScriptFailure(['echo v:null != 123'], 'E1072: Cannot compare special with number') - v9.CheckDefAndScriptFailure(['echo true == v:null'], 'E1072: Cannot compare bool with special') - v9.CheckDefAndScriptFailure(['echo v:null == true'], 'E1072: Cannot compare special with bool') - v9.CheckDefAndScriptFailure(['echo true != v:null'], 'E1072: Cannot compare bool with special') - v9.CheckDefAndScriptFailure(['echo v:null != true'], 'E1072: Cannot compare special with bool') - v9.CheckDefAndScriptFailure(['echo false == v:null'], 'E1072: Cannot compare bool with special') enddef def Test_expr4_compare_none() --- 847,852 ---- *** ../vim-8.2.4575/src/version.c 2022-03-15 19:29:26.546954678 +0000 --- src/version.c 2022-03-15 20:04:58.915011429 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4576, /**/ -- Women are probably the main cause of free software starvation. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///