Mercurial > vim
diff src/vim9execute.c @ 22238:939f7184566f v8.2.1668
patch 8.2.1668: Vim9: not accepting 0 or 1 as bool when type is any
Commit: https://github.com/vim/vim/commit/dadaddd59f3b53c41e92dc42219ab006deb14109
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 12 19:11:23 2020 +0200
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 https://github.com/vim/vim/issues/6913)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 12 Sep 2020 19:15:03 +0200 |
parents | efa1511a5bf3 |
children | 3f082bd15d29 |
line wrap: on
line diff
--- 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;