To: vim_dev@googlegroups.com Subject: Patch 8.2.1416 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1416 Problem: Vim9: boolean evaluation does not work as intended. Solution: Use tv2bool() in Vim9 script. (closes #6681) Files: src/eval.c, src/testdir/test_vim9_expr.vim, src/testdir/vim9.vim *** ../vim-8.2.1415/src/eval.c 2020-08-09 22:17:52.709512974 +0200 --- src/eval.c 2020-08-10 21:55:31.715790442 +0200 *************** *** 192,198 **** *error = FALSE; if (!skip) { ! retval = (tv_get_number_chk(&tv, error) != 0); clear_tv(&tv); } } --- 192,201 ---- *error = FALSE; if (!skip) { ! if (in_vim9script()) ! retval = tv2bool(&tv); ! else ! retval = (tv_get_number_chk(&tv, error) != 0); clear_tv(&tv); } } *************** *** 3098,3104 **** // Apply prefixed "-" and "+" now. Matters especially when // "->" follows. ! if (ret == OK && evaluate && end_leader > start_leader) ret = eval7_leader(rettv, TRUE, start_leader, &end_leader); break; --- 3101,3108 ---- // Apply prefixed "-" and "+" now. Matters especially when // "->" follows. ! if (ret == OK && evaluate && end_leader > start_leader ! && rettv->v_type != VAR_BLOB) ret = eval7_leader(rettv, TRUE, start_leader, &end_leader); break; *************** *** 3281,3287 **** f = rettv->vval.v_float; else #endif ! val = tv_get_number_chk(rettv, &error); if (error) { clear_tv(rettv); --- 3285,3294 ---- f = rettv->vval.v_float; else #endif ! if (in_vim9script() && end_leader[-1] == '!') ! val = tv2bool(rettv); ! else ! val = tv_get_number_chk(rettv, &error); if (error) { clear_tv(rettv); *** ../vim-8.2.1415/src/testdir/test_vim9_expr.vim 2020-08-09 22:17:52.709512974 +0200 --- src/testdir/test_vim9_expr.vim 2020-08-10 21:43:21.394674260 +0200 *************** *** 1750,1780 **** def Test_expr7_not() ! assert_equal(true, !'') ! assert_equal(true, ![]) ! assert_equal(false, !'asdf') ! assert_equal(false, ![2]) ! assert_equal(true, !!'asdf') ! assert_equal(true, !![2]) ! ! assert_equal(true, !test_null_partial()) ! assert_equal(false, !{-> 'yes'}) ! ! assert_equal(true, !test_null_dict()) ! assert_equal(true, !{}) ! assert_equal(false, !{'yes': 'no'}) ! ! if has('channel') ! assert_equal(true, !test_null_job()) ! assert_equal(true, !test_null_channel()) ! endif ! ! assert_equal(true, !test_null_blob()) ! assert_equal(true, !0z) ! assert_equal(false, !0z01) ! ! assert_equal(true, !test_void()) ! assert_equal(true, !test_unknown()) enddef func Test_expr7_fails() --- 1750,1784 ---- def Test_expr7_not() ! let lines =<< trim END ! assert_equal(true, !'') ! assert_equal(true, ![]) ! assert_equal(false, !'asdf') ! assert_equal(false, ![2]) ! assert_equal(true, !!'asdf') ! assert_equal(true, !![2]) ! ! assert_equal(true, !test_null_partial()) ! assert_equal(false, !{-> 'yes'}) ! ! assert_equal(true, !test_null_dict()) ! assert_equal(true, !{}) ! assert_equal(false, !{'yes': 'no'}) ! ! if has('channel') ! assert_equal(true, !test_null_job()) ! assert_equal(true, !test_null_channel()) ! endif ! ! assert_equal(true, !test_null_blob()) ! assert_equal(true, !0z) ! assert_equal(false, !0z01) ! ! assert_equal(true, !test_void()) ! assert_equal(true, !test_unknown()) ! END ! CheckDefSuccess(lines) ! CheckScriptSuccess(['vim9script'] + lines) enddef func Test_expr7_fails() *** ../vim-8.2.1415/src/testdir/vim9.vim 2020-05-24 23:00:06.444196001 +0200 --- src/testdir/vim9.vim 2020-08-10 21:39:38.803514548 +0200 *************** *** 1,5 **** --- 1,13 ---- " Utility functions for testing vim9 script + " Check that "lines" inside ":def" has no error. + func CheckDefSuccess(lines) + call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef') + so Xdef + call Func() + call delete('Xdef') + endfunc + " Check that "lines" inside ":def" results in an "error" message. func CheckDefFailure(lines, error) call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef') *** ../vim-8.2.1415/src/version.c 2020-08-10 21:19:04.287641781 +0200 --- src/version.c 2020-08-10 21:30:25.197400623 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1416, /**/ -- In Joseph Heller's novel "Catch-22", the main character tries to get out of a war by proving he is crazy. But the mere fact he wants to get out of the war only shows he isn't crazy -- creating the original "Catch-22". /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///