0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.1668: Vim9: not accepting 0 or 1 as bool when type is any

Problem:    Vim9: not accepting 0 or 1 as bool when type is any.
Solution:   Convert the type with the CHECKTYPE instruction. (closes #6913)
This commit is contained in:
Bram Moolenaar 2020-09-12 19:11:23 +02:00
parent 0f769815c8
commit dadaddd59f
3 changed files with 22 additions and 5 deletions

View File

@ -2369,6 +2369,9 @@ def Test_expr7_method_call()
type: '',
module: ''}
], getloclist(0))
let result: bool = get(#{n: 0}, 'n', 0)
assert_equal(false, result)
enddef
func Test_expr7_trailing_fails()

View File

@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1668,
/**/
1667,
/**/

View File

@ -2509,6 +2509,17 @@ call_def_function(
&& ct->ct_type == VAR_FUNC)
|| (tv->v_type == VAR_FUNC
&& ct->ct_type == VAR_PARTIAL)))
{
if (tv->v_type == VAR_NUMBER && ct->ct_type == VAR_BOOL
&& (tv->vval.v_number == 0
|| tv->vval.v_number == 1))
{
// number 0 is FALSE, number 1 is TRUE
tv->v_type = VAR_BOOL;
tv->vval.v_number = tv->vval.v_number
? VVAL_TRUE : VVAL_FALSE;
}
else
{
SOURCING_LNUM = iptr->isn_lnum;
semsg(_(e_expected_str_but_got_str),
@ -2517,6 +2528,7 @@ call_def_function(
goto on_error;
}
}
}
break;
case ISN_CHECKLEN: