summaryrefslogtreecommitdiff
path: root/src/vim9instr.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-02-01 12:11:58 +0000
committerBram Moolenaar <Bram@vim.org>2022-02-01 12:11:58 +0000
commit8133018f50bc447570825801e93d5ed67e8dac90 (patch)
treeb59670eb8f761b319fad4ead8098674f603cede5 /src/vim9instr.c
parent4e3b3182307444f205a5f35e257c651f0f3717ad (diff)
downloadvim-git-8133018f50bc447570825801e93d5ed67e8dac90.tar.gz
patch 8.2.4279: Vim9: cannot change item type with map() after range()v8.2.4279
Problem: Vim9: cannot change item type with map() after range(). Solution: Split the return type in current type and declared type. (closes #9665)
Diffstat (limited to 'src/vim9instr.c')
-rw-r--r--src/vim9instr.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/vim9instr.c b/src/vim9instr.c
index e869d9ea6..60963a3c9 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -1078,7 +1078,8 @@ generate_NEWLIST(cctx_T *cctx, int count)
// Get the member type and the declared member type from all the items on
// the stack.
- member_type = get_member_type_from_stack(count, 1, &decl_member_type, cctx);
+ member_type = get_member_type_from_stack(count, 1,
+ &decl_member_type, cctx);
type = get_list_type(member_type, cctx->ctx_type_list);
decl_type = get_list_type(decl_member_type, cctx->ctx_type_list);
@@ -1277,6 +1278,7 @@ generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call)
type2_T shuffled_argtypes[MAX_FUNC_ARGS];
type2_T *maptype = NULL;
type_T *type;
+ type_T *decl_type;
RETURN_OK_IF_SKIP(cctx);
argoff = check_internal_func(func_idx, argcount);
@@ -1327,8 +1329,8 @@ generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call)
// Drop the argument types and push the return type.
stack->ga_len -= argcount;
- type = internal_func_ret_type(func_idx, argcount, argtypes);
- if (push_type_stack(cctx, type) == FAIL)
+ type = internal_func_ret_type(func_idx, argcount, argtypes, &decl_type);
+ if (push_type_stack2(cctx, type, decl_type) == FAIL)
return FAIL;
if (maptype != NULL && maptype[0].type_decl->tt_member != NULL
@@ -1351,7 +1353,9 @@ generate_LISTAPPEND(cctx_T *cctx)
type_T *expected;
// Caller already checked that list_type is a list.
- list_type = get_type_on_stack(cctx, 1);
+ // For checking the item type we use the declared type of the list and the
+ // current type of the added item, adding a string to [1, 2] is OK.
+ list_type = get_decl_type_on_stack(cctx, 1);
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)