patch 9.0.1108: type error when using "any" type and adding to float
Problem: Type error when using "any" type and adding a number to a float.
Solution: Accept both a number and a float. (closes #11753)
diff --git a/src/vim9expr.c b/src/vim9expr.c
index b4e201e..ba2c826 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -99,13 +99,14 @@
vartype = VAR_DICT;
if (vartype == VAR_STRING || vartype == VAR_LIST || vartype == VAR_BLOB)
{
- if (need_type(idxtype, &t_number, -1, 0, cctx, FALSE, FALSE) == FAIL)
+ if (need_type(idxtype, &t_number, FALSE,
+ -1, 0, cctx, FALSE, FALSE) == FAIL)
return FAIL;
if (is_slice)
{
idxtype = get_type_on_stack(cctx, 1);
- if (need_type(idxtype, &t_number, -2, 0, cctx,
- FALSE, FALSE) == FAIL)
+ if (need_type(idxtype, &t_number, FALSE,
+ -2, 0, cctx, FALSE, FALSE) == FAIL)
return FAIL;
}
}
@@ -135,8 +136,8 @@
}
else
{
- if (need_type(typep->type_curr, &t_dict_any, -2, 0, cctx,
- FALSE, FALSE) == FAIL)
+ if (need_type(typep->type_curr, &t_dict_any, FALSE,
+ -2, 0, cctx, FALSE, FALSE) == FAIL)
return FAIL;
typep->type_curr = &t_any;
typep->type_decl = &t_any;
@@ -1725,7 +1726,7 @@
// This requires a runtime type check.
return generate_COND2BOOL(cctx);
- return need_type(type, &t_bool, -1, 0, cctx, FALSE, FALSE);
+ return need_type(type, &t_bool, FALSE, -1, 0, cctx, FALSE, FALSE);
}
/*
@@ -1759,7 +1760,7 @@
{
type_T *type = get_type_on_stack(cctx, 0);
if (type->tt_type != VAR_FLOAT && need_type(type, &t_number,
- -1, 0, cctx, FALSE, FALSE) == FAIL)
+ FALSE, -1, 0, cctx, FALSE, FALSE) == FAIL)
return FAIL;
// only '-' has an effect, for '+' we only check the type
@@ -2517,8 +2518,8 @@
actual = get_type_on_stack(cctx, 0);
if (check_type_maybe(want_type, actual, FALSE, where) != OK)
{
- if (need_type(actual, want_type, -1, 0, cctx, FALSE, FALSE)
- == FAIL)
+ if (need_type(actual, want_type, FALSE,
+ -1, 0, cctx, FALSE, FALSE) == FAIL)
return FAIL;
}
}
@@ -2759,7 +2760,7 @@
{
type_T *t = get_type_on_stack(cctx, 0);
- if (need_type(t, &t_number, 0, 0, cctx, FALSE, FALSE) == FAIL)
+ if (need_type(t, &t_number, FALSE, 0, 0, cctx, FALSE, FALSE) == FAIL)
{
emsg(_(e_bitshift_ops_must_be_number));
return FAIL;
@@ -2814,8 +2815,8 @@
}
else
{
- if (need_type(get_type_on_stack(cctx, 0), &t_number, 0, 0, cctx,
- FALSE, FALSE) == FAIL)
+ if (need_type(get_type_on_stack(cctx, 0), &t_number, FALSE,
+ 0, 0, cctx, FALSE, FALSE) == FAIL)
{
emsg(_(e_bitshift_ops_must_be_number));
return FAIL;