patch 8.2.3866: Vim9: type checking global variables is inconsistent
Problem: Vim9: type checking global variables is inconsistent.
Solution: Use the "unknown" type in more places.
diff --git a/src/vim9instr.c b/src/vim9instr.c
index 48c90dc..06d6b90 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -168,9 +168,10 @@
static int
check_number_or_float(vartype_T type1, vartype_T type2, char_u *op)
{
- if (!((type1 == VAR_NUMBER || type1 == VAR_FLOAT || type1 == VAR_ANY)
+ if (!((type1 == VAR_NUMBER || type1 == VAR_FLOAT
+ || type1 == VAR_ANY || type1 == VAR_UNKNOWN)
&& (type2 == VAR_NUMBER || type2 == VAR_FLOAT
- || type2 == VAR_ANY)))
+ || type2 == VAR_ANY || type2 == VAR_UNKNOWN)))
{
if (*op == '+')
emsg(_(e_wrong_argument_type_for_plus));
@@ -204,7 +205,9 @@
if (vartype != VAR_LIST && vartype != VAR_BLOB
&& type1->tt_type != VAR_ANY
+ && type1->tt_type != VAR_UNKNOWN
&& type2->tt_type != VAR_ANY
+ && type2->tt_type != VAR_UNKNOWN
&& check_number_or_float(
type1->tt_type, type2->tt_type, (char_u *)"+") == FAIL)
return FAIL;
@@ -293,8 +296,10 @@
break;
case '%': if ((type1->tt_type != VAR_ANY
+ && type1->tt_type != VAR_UNKNOWN
&& type1->tt_type != VAR_NUMBER)
|| (type2->tt_type != VAR_ANY
+ && type2->tt_type != VAR_UNKNOWN
&& type2->tt_type != VAR_NUMBER))
{
emsg(_(e_percent_requires_number_arguments));
@@ -1528,7 +1533,7 @@
RETURN_OK_IF_SKIP(cctx);
- if (type->tt_type == VAR_ANY)
+ if (type->tt_type == VAR_ANY || type->tt_type == VAR_UNKNOWN)
ret_type = &t_any;
else if (type->tt_type == VAR_FUNC || type->tt_type == VAR_PARTIAL)
{
@@ -1620,7 +1625,7 @@
// check for dict type
type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
- if (type->tt_type != VAR_DICT && type != &t_any)
+ if (type->tt_type != VAR_DICT && type != &t_any && type != &t_unknown)
{
char *tofree;