summaryrefslogtreecommitdiff
path: root/src/vim9compile.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-09-09 14:55:31 +0200
committerBram Moolenaar <Bram@vim.org>2020-09-09 14:55:31 +0200
commit29a86ffee794bc1a0efde215c203cf9529047252 (patch)
treee718319396ca7a66a071c72fb02af88db2426e3f /src/vim9compile.c
parentf842cd9e285afb9d86c6f9bff400e5e576f873c0 (diff)
downloadvim-git-8.2.1641.tar.gz
patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expectedv8.2.1641
Problem: Vim9: cannot use 0 or 1 where a bool is expected. Solution: Allow using 0 and 1 for a bool type. (closes #6903)
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r--src/vim9compile.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 8b1dcd5d5..f88f3a3df 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -751,12 +751,25 @@ need_type(
generate_PUSHNR(cctx_T *cctx, varnumber_T number)
{
isn_T *isn;
+ garray_T *stack = &cctx->ctx_type_stack;
RETURN_OK_IF_SKIP(cctx);
if ((isn = generate_instr_type(cctx, ISN_PUSHNR, &t_number)) == NULL)
return FAIL;
isn->isn_arg.number = number;
+ if (number == 0 || number == 1)
+ {
+ type_T *type = alloc_type(cctx->ctx_type_list);
+
+ // A 0 or 1 number can also be used as a bool.
+ if (type != NULL)
+ {
+ type->tt_type = VAR_NUMBER;
+ type->tt_flags = TTFLAG_BOOL_OK;
+ ((type_T **)stack->ga_data)[stack->ga_len - 1] = type;
+ }
+ }
return OK;
}