From 29a86ffee794bc1a0efde215c203cf9529047252 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 9 Sep 2020 14:55:31 +0200 Subject: patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected Problem: Vim9: cannot use 0 or 1 where a bool is expected. Solution: Allow using 0 and 1 for a bool type. (closes #6903) --- src/vim9compile.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/vim9compile.c') 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; } -- cgit v1.2.1