patch 8.2.1407: Vim9: type of list and dict only depends on first item
Problem: Vim9: type of list and dict only depends on first item.
Solution: Use all items to decide about the type.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index e23dd7a..19760fb 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1110,17 +1110,15 @@
return FAIL;
isn->isn_arg.number = count;
+ // get the member type from all the items on the stack.
+ member = get_member_type_from_stack(
+ ((type_T **)stack->ga_data) + stack->ga_len, count, 1,
+ cctx->ctx_type_list);
+ type = get_list_type(member, cctx->ctx_type_list);
+
// drop the value types
stack->ga_len -= count;
- // Use the first value type for the list member type. Use "any" for an
- // empty list.
- if (count > 0)
- member = ((type_T **)stack->ga_data)[stack->ga_len];
- else
- member = &t_void;
- type = get_list_type(member, cctx->ctx_type_list);
-
// add the list type to the type stack
if (ga_grow(stack, 1) == FAIL)
return FAIL;
@@ -1146,17 +1144,14 @@
return FAIL;
isn->isn_arg.number = count;
+ member = get_member_type_from_stack(
+ ((type_T **)stack->ga_data) + stack->ga_len, count, 2,
+ cctx->ctx_type_list);
+ type = get_dict_type(member, cctx->ctx_type_list);
+
// drop the key and value types
stack->ga_len -= 2 * count;
- // Use the first value type for the list member type. Use "void" for an
- // empty dict.
- if (count > 0)
- member = ((type_T **)stack->ga_data)[stack->ga_len + 1];
- else
- member = &t_void;
- type = get_dict_type(member, cctx->ctx_type_list);
-
// add the dict type to the type stack
if (ga_grow(stack, 1) == FAIL)
return FAIL;