summaryrefslogtreecommitdiff
path: root/src/typval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-08-22 15:06:35 +0200
committerBram Moolenaar <Bram@vim.org>2020-08-22 15:06:35 +0200
commitd70840ed68296c1144d743e6335003c81c558c24 (patch)
tree2fe663bae5737733924e71796559725f5be472ad /src/typval.c
parent1b04ce2d400fda97410a961288c496bd8f445a9c (diff)
downloadvim-git-d70840ed68296c1144d743e6335003c81c558c24.tar.gz
patch 8.2.1506: Vim9: no error when using a number other than 0 or 1 as boolv8.2.1506
Problem: Vim9: no error when using a number other than 0 or 1 as bool. Solution: Check the number is 0 or 1.
Diffstat (limited to 'src/typval.c')
-rw-r--r--src/typval.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/typval.c b/src/typval.c
index 2203bc6fa..d1732f2b7 100644
--- a/src/typval.c
+++ b/src/typval.c
@@ -177,6 +177,12 @@ tv_get_bool_or_number_chk(typval_T *varp, int *denote, int want_bool)
switch (varp->v_type)
{
case VAR_NUMBER:
+ if (want_bool && varp->vval.v_number != 0
+ && varp->vval.v_number != 1)
+ {
+ semsg(_(e_using_number_as_bool_nr), varp->vval.v_number);
+ break;
+ }
return varp->vval.v_number;
case VAR_FLOAT:
#ifdef FEAT_FLOAT
@@ -261,13 +267,12 @@ tv_get_number_chk(typval_T *varp, int *denote)
/*
* Get the boolean value of "varp". This is like tv_get_number_chk(),
- * but in Vim9 script accepts Number and Bool.
+ * but in Vim9 script accepts Number (0 and 1) and Bool/Special.
*/
varnumber_T
tv_get_bool(typval_T *varp)
{
return tv_get_bool_or_number_chk(varp, NULL, TRUE);
-
}
/*