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)
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 8b1dcd5..f88f3a3 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -751,12 +751,25 @@
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;
}