To: vim_dev@googlegroups.com Subject: Patch 8.2.2755 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2755 Problem: Vim9: no error for using a number in a condition. Solution: Also use ISN_COND2BOOL if the type is t_number_bool. (closes #7644) Files: src/vim9compile.c, src/testdir/test_vim9_expr.vim, src/testdir/test_vim9_disassemble.vim *** ../vim-8.2.2754/src/vim9compile.c 2021-04-10 22:35:40.487360271 +0200 --- src/vim9compile.c 2021-04-11 18:12:53.556420307 +0200 *************** *** 990,996 **** if (type == &t_bool) return OK; ! if (type == &t_any || type == &t_number) // Number 0 and 1 are OK to use as a bool. "any" could also be a bool. // This requires a runtime type check. return generate_COND2BOOL(cctx); --- 990,996 ---- if (type == &t_bool) return OK; ! if (type == &t_any || type == &t_number || type == &t_number_bool) // Number 0 and 1 are OK to use as a bool. "any" could also be a bool. // This requires a runtime type check. return generate_COND2BOOL(cctx); *** ../vim-8.2.2754/src/testdir/test_vim9_expr.vim 2021-04-07 21:58:13.203566847 +0200 --- src/testdir/test_vim9_expr.vim 2021-04-11 18:23:25.758714232 +0200 *************** *** 282,287 **** --- 282,301 ---- g:vals = [] assert_equal(false, Record(0) || Record(false) || Record(0)) assert_equal([0, false, 0], g:vals) + + g:vals = [] + var x = 1 + if x || true + g:vals = [1] + endif + assert_equal([1], g:vals) + + g:vals = [] + x = 3 + if true || x + g:vals = [1] + endif + assert_equal([1], g:vals) END CheckDefAndScriptSuccess(lines) enddef *************** *** 357,362 **** --- 371,379 ---- # TODO: should fail at compile time call CheckDefExecAndScriptFailure(["var x = 3 || 7"], 'E1023:', 1) + call CheckDefAndScriptFailure(["if 3"], 'E1023:', 1) + call CheckDefExecAndScriptFailure(['var x = 3', 'if x', 'endif'], 'E1023:', 2) + call CheckDefAndScriptFailure2(["var x = [] || false"], 'E1012: Type mismatch; expected bool but got list', 'E745:', 1) enddef *** ../vim-8.2.2754/src/testdir/test_vim9_disassemble.vim 2021-03-29 22:14:45.608788413 +0200 --- src/testdir/test_vim9_disassemble.vim 2021-04-11 18:20:21.255218982 +0200 *************** *** 770,776 **** 'if has("gui_running")\_s*' .. '\d PUSHS "gui_running"\_s*' .. '\d BCALL has(argc 1)\_s*' .. ! '\d 2BOOL (!!val)\_s*' .. '\d JUMP_IF_FALSE -> \d\_s*' .. ' echo "yes"\_s*' .. '\d PUSHS "yes"\_s*' .. --- 770,776 ---- 'if has("gui_running")\_s*' .. '\d PUSHS "gui_running"\_s*' .. '\d BCALL has(argc 1)\_s*' .. ! '\d COND2BOOL\_s*' .. '\d JUMP_IF_FALSE -> \d\_s*' .. ' echo "yes"\_s*' .. '\d PUSHS "yes"\_s*' .. *************** *** 1537,1549 **** assert_match('ReturnBool\_s*' .. 'var name: bool = 1 && 0 || 1\_s*' .. '0 PUSHNR 1\_s*' .. ! '1 2BOOL (!!val)\_s*' .. '2 JUMP_IF_COND_FALSE -> 5\_s*' .. '3 PUSHNR 0\_s*' .. ! '4 2BOOL (!!val)\_s*' .. '5 JUMP_IF_COND_TRUE -> 8\_s*' .. '6 PUSHNR 1\_s*' .. ! '7 2BOOL (!!val)\_s*' .. '\d STORE $0\_s*' .. 'return name\_s*' .. '\d\+ LOAD $0\_s*' .. --- 1537,1549 ---- assert_match('ReturnBool\_s*' .. 'var name: bool = 1 && 0 || 1\_s*' .. '0 PUSHNR 1\_s*' .. ! '1 COND2BOOL\_s*' .. '2 JUMP_IF_COND_FALSE -> 5\_s*' .. '3 PUSHNR 0\_s*' .. ! '4 COND2BOOL\_s*' .. '5 JUMP_IF_COND_TRUE -> 8\_s*' .. '6 PUSHNR 1\_s*' .. ! '7 COND2BOOL\_s*' .. '\d STORE $0\_s*' .. 'return name\_s*' .. '\d\+ LOAD $0\_s*' .. *** ../vim-8.2.2754/src/version.c 2021-04-11 13:29:13.198824331 +0200 --- src/version.c 2021-04-11 18:14:17.548195114 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2755, /**/ -- From "know your smileys": +<(:-) The Pope /// 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 ///