summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-09-12 19:11:23 +0200
committerBram Moolenaar <Bram@vim.org>2020-09-12 19:11:23 +0200
commitdadaddd59f3b53c41e92dc42219ab006deb14109 (patch)
treeb0fecbbed4c3a77ee11072940f404e8d62ca440f
parent0f769815c82bf93812842e1ad56fcc52c10ff3e5 (diff)
patch 8.2.1668: Vim9: not accepting 0 or 1 as bool when type is anyv8.2.1668
Problem: Vim9: not accepting 0 or 1 as bool when type is any. Solution: Convert the type with the CHECKTYPE instruction. (closes #6913)
-rw-r--r--src/testdir/test_vim9_expr.vim3
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c22
3 files changed, 22 insertions, 5 deletions
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 8cf5bc0d60..15fc3aeea1 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -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()
diff --git a/src/version.c b/src/version.c
index b225f7406c..305f0cb707 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1668,
+/**/
1667,
/**/
1666,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 18cfb0213b..e93817a62b 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2510,11 +2510,23 @@ call_def_function(
|| (tv->v_type == VAR_FUNC
&& ct->ct_type == VAR_PARTIAL)))
{
- SOURCING_LNUM = iptr->isn_lnum;
- semsg(_(e_expected_str_but_got_str),
- vartype_name(ct->ct_type),
- vartype_name(tv->v_type));
- goto on_error;
+ 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),
+ vartype_name(ct->ct_type),
+ vartype_name(tv->v_type));
+ goto on_error;
+ }
}
}
break;