0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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)
This commit is contained in:
Bram Moolenaar
2022-12-29 20:56:24 +00:00
parent 73ade49c4b
commit c6951a76a5
12 changed files with 117 additions and 54 deletions

View File

@@ -576,6 +576,7 @@ generate_COND2BOOL(cctx_T *cctx)
generate_TYPECHECK(
cctx_T *cctx,
type_T *expected,
int number_ok, // add TTFLAG_NUMBER_OK flag
int offset,
int is_var,
int argidx)
@@ -585,7 +586,21 @@ generate_TYPECHECK(
RETURN_OK_IF_SKIP(cctx);
if ((isn = generate_instr(cctx, ISN_CHECKTYPE)) == NULL)
return FAIL;
isn->isn_arg.type.ct_type = alloc_type(expected);
type_T *tt;
if (expected->tt_type == VAR_FLOAT && number_ok)
{
// always allocate, also for static types
tt = ALLOC_ONE(type_T);
if (tt != NULL)
{
*tt = *expected;
tt->tt_flags |= TTFLAG_NUMBER_OK;
}
}
else
tt = alloc_type(expected);
isn->isn_arg.type.ct_type = tt;
isn->isn_arg.type.ct_off = (int8_T)offset;
isn->isn_arg.type.ct_is_var = is_var;
isn->isn_arg.type.ct_arg_idx = (int8_T)argidx;
@@ -1601,7 +1616,7 @@ generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call)
if (maptype != NULL && maptype[0].type_decl->tt_member != NULL
&& maptype[0].type_decl->tt_member != &t_any)
// Check that map() didn't change the item types.
generate_TYPECHECK(cctx, maptype[0].type_decl, -1, FALSE, 1);
generate_TYPECHECK(cctx, maptype[0].type_decl, FALSE, -1, FALSE, 1);
return OK;
}
@@ -1625,7 +1640,7 @@ generate_LISTAPPEND(cctx_T *cctx)
return FAIL;
item_type = get_type_on_stack(cctx, 0);
expected = list_type->tt_member;
if (need_type(item_type, expected, -1, 0, cctx, FALSE, FALSE) == FAIL)
if (need_type(item_type, expected, FALSE, -1, 0, cctx, FALSE, FALSE) == FAIL)
return FAIL;
if (generate_instr(cctx, ISN_LISTAPPEND) == NULL)
@@ -1648,7 +1663,8 @@ generate_BLOBAPPEND(cctx_T *cctx)
if (arg_type_modifiable(get_decl_type_on_stack(cctx, 1), 1) == FAIL)
return FAIL;
item_type = get_type_on_stack(cctx, 0);
if (need_type(item_type, &t_number, -1, 0, cctx, FALSE, FALSE) == FAIL)
if (need_type(item_type, &t_number, FALSE,
-1, 0, cctx, FALSE, FALSE) == FAIL)
return FAIL;
if (generate_instr(cctx, ISN_BLOBAPPEND) == NULL)
@@ -1713,8 +1729,8 @@ generate_CALL(cctx_T *cctx, ufunc_T *ufunc, int pushed_argcount)
expected = &t_any;
else
expected = ufunc->uf_va_type->tt_member;
if (need_type(actual, expected, -argcount + i, i + 1, cctx,
TRUE, FALSE) == FAIL)
if (need_type(actual, expected, FALSE,
-argcount + i, i + 1, cctx, TRUE, FALSE) == FAIL)
{
arg_type_mismatch(expected, actual, i + 1);
return FAIL;
@@ -1821,8 +1837,8 @@ check_func_args_from_type(
expected = &t_any;
else
expected = type->tt_args[i];
if (need_type(actual, expected, offset, i + 1,
cctx, TRUE, FALSE) == FAIL)
if (need_type(actual, expected, FALSE,
offset, i + 1, cctx, TRUE, FALSE) == FAIL)
{
arg_type_mismatch(expected, actual, i + 1);
return FAIL;