Mercurial > vim
diff src/vim9type.c @ 22190:da851f3b6a0b v8.2.1644
patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Commit: https://github.com/vim/vim/commit/ba7c0d7b4ce03336b4aebe1959c1a8342fa6dbd4
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Sep 9 18:54:42 2020 +0200
patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Problem: Vim9: cannot assign 1 and 0 to bool at script level.
Solution: Add the TTFLAG_BOOL_OK flag to the type. Fix name of test
function.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 09 Sep 2020 19:00:04 +0200 |
parents | 2463b3d89ce2 |
children | 7899b4e2880c |
line wrap: on
line diff
--- a/src/vim9type.c +++ b/src/vim9type.c @@ -202,11 +202,23 @@ func_type_add_arg_types( type_T * typval2type(typval_T *tv, garray_T *type_gap) { - type_T *actual; + type_T *type; type_T *member_type; if (tv->v_type == VAR_NUMBER) + { + if (tv->vval.v_number == 0 || tv->vval.v_number == 1) + { + // number 0 and 1 can also be used for bool + type = alloc_type(type_gap); + if (type == NULL) + return NULL; + type->tt_type = VAR_NUMBER; + type->tt_flags = TTFLAG_BOOL_OK; + return type; + } return &t_number; + } if (tv->v_type == VAR_BOOL) return &t_bool; // not used if (tv->v_type == VAR_STRING) @@ -276,13 +288,13 @@ typval2type(typval_T *tv, garray_T *type } } - actual = alloc_type(type_gap); - if (actual == NULL) + type = alloc_type(type_gap); + if (type == NULL) return NULL; - actual->tt_type = tv->v_type; - actual->tt_member = &t_any; + type->tt_type = tv->v_type; + type->tt_member = &t_any; - return actual; + return type; } /*