mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2755: Vim9: no error for using a number in a condition
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)
This commit is contained in:
@@ -770,7 +770,7 @@ def Test_disassemble_const_expr()
|
|||||||
'if has("gui_running")\_s*' ..
|
'if has("gui_running")\_s*' ..
|
||||||
'\d PUSHS "gui_running"\_s*' ..
|
'\d PUSHS "gui_running"\_s*' ..
|
||||||
'\d BCALL has(argc 1)\_s*' ..
|
'\d BCALL has(argc 1)\_s*' ..
|
||||||
'\d 2BOOL (!!val)\_s*' ..
|
'\d COND2BOOL\_s*' ..
|
||||||
'\d JUMP_IF_FALSE -> \d\_s*' ..
|
'\d JUMP_IF_FALSE -> \d\_s*' ..
|
||||||
' echo "yes"\_s*' ..
|
' echo "yes"\_s*' ..
|
||||||
'\d PUSHS "yes"\_s*' ..
|
'\d PUSHS "yes"\_s*' ..
|
||||||
@@ -1537,13 +1537,13 @@ def Test_disassemble_return_bool()
|
|||||||
assert_match('ReturnBool\_s*' ..
|
assert_match('ReturnBool\_s*' ..
|
||||||
'var name: bool = 1 && 0 || 1\_s*' ..
|
'var name: bool = 1 && 0 || 1\_s*' ..
|
||||||
'0 PUSHNR 1\_s*' ..
|
'0 PUSHNR 1\_s*' ..
|
||||||
'1 2BOOL (!!val)\_s*' ..
|
'1 COND2BOOL\_s*' ..
|
||||||
'2 JUMP_IF_COND_FALSE -> 5\_s*' ..
|
'2 JUMP_IF_COND_FALSE -> 5\_s*' ..
|
||||||
'3 PUSHNR 0\_s*' ..
|
'3 PUSHNR 0\_s*' ..
|
||||||
'4 2BOOL (!!val)\_s*' ..
|
'4 COND2BOOL\_s*' ..
|
||||||
'5 JUMP_IF_COND_TRUE -> 8\_s*' ..
|
'5 JUMP_IF_COND_TRUE -> 8\_s*' ..
|
||||||
'6 PUSHNR 1\_s*' ..
|
'6 PUSHNR 1\_s*' ..
|
||||||
'7 2BOOL (!!val)\_s*' ..
|
'7 COND2BOOL\_s*' ..
|
||||||
'\d STORE $0\_s*' ..
|
'\d STORE $0\_s*' ..
|
||||||
'return name\_s*' ..
|
'return name\_s*' ..
|
||||||
'\d\+ LOAD $0\_s*' ..
|
'\d\+ LOAD $0\_s*' ..
|
||||||
|
@@ -282,6 +282,20 @@ def Test_expr2()
|
|||||||
g:vals = []
|
g:vals = []
|
||||||
assert_equal(false, Record(0) || Record(false) || Record(0))
|
assert_equal(false, Record(0) || Record(false) || Record(0))
|
||||||
assert_equal([0, false, 0], g:vals)
|
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
|
END
|
||||||
CheckDefAndScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
@@ -357,6 +371,9 @@ def Test_expr2_fails()
|
|||||||
# TODO: should fail at compile time
|
# TODO: should fail at compile time
|
||||||
call CheckDefExecAndScriptFailure(["var x = 3 || 7"], 'E1023:', 1)
|
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<unknown>', 'E745:', 1)
|
call CheckDefAndScriptFailure2(["var x = [] || false"], 'E1012: Type mismatch; expected bool but got list<unknown>', 'E745:', 1)
|
||||||
|
|
||||||
enddef
|
enddef
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2755,
|
||||||
/**/
|
/**/
|
||||||
2754,
|
2754,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -990,7 +990,7 @@ bool_on_stack(cctx_T *cctx)
|
|||||||
if (type == &t_bool)
|
if (type == &t_bool)
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
if (type == &t_any || type == &t_number)
|
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.
|
// Number 0 and 1 are OK to use as a bool. "any" could also be a bool.
|
||||||
// This requires a runtime type check.
|
// This requires a runtime type check.
|
||||||
return generate_COND2BOOL(cctx);
|
return generate_COND2BOOL(cctx);
|
||||||
|
Reference in New Issue
Block a user