comparison src/vim9compile.c @ 21715:571832713efa v8.2.1407

patch 8.2.1407: Vim9: type of list and dict only depends on first item Commit: https://github.com/vim/vim/commit/127542bcebeb6480493b09d75a3be1d98a5f7797 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 9 17:22:04 2020 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Sun, 09 Aug 2020 17:30:03 +0200
parents d2dee69de7c7
children ef3b31d510d2
comparison
equal deleted inserted replaced
21714:e5d6e27da443 21715:571832713efa
1108 RETURN_OK_IF_SKIP(cctx); 1108 RETURN_OK_IF_SKIP(cctx);
1109 if ((isn = generate_instr(cctx, ISN_NEWLIST)) == NULL) 1109 if ((isn = generate_instr(cctx, ISN_NEWLIST)) == NULL)
1110 return FAIL; 1110 return FAIL;
1111 isn->isn_arg.number = count; 1111 isn->isn_arg.number = count;
1112 1112
1113 // get the member type from all the items on the stack.
1114 member = get_member_type_from_stack(
1115 ((type_T **)stack->ga_data) + stack->ga_len, count, 1,
1116 cctx->ctx_type_list);
1117 type = get_list_type(member, cctx->ctx_type_list);
1118
1113 // drop the value types 1119 // drop the value types
1114 stack->ga_len -= count; 1120 stack->ga_len -= count;
1115
1116 // Use the first value type for the list member type. Use "any" for an
1117 // empty list.
1118 if (count > 0)
1119 member = ((type_T **)stack->ga_data)[stack->ga_len];
1120 else
1121 member = &t_void;
1122 type = get_list_type(member, cctx->ctx_type_list);
1123 1121
1124 // add the list type to the type stack 1122 // add the list type to the type stack
1125 if (ga_grow(stack, 1) == FAIL) 1123 if (ga_grow(stack, 1) == FAIL)
1126 return FAIL; 1124 return FAIL;
1127 ((type_T **)stack->ga_data)[stack->ga_len] = type; 1125 ((type_T **)stack->ga_data)[stack->ga_len] = type;
1144 RETURN_OK_IF_SKIP(cctx); 1142 RETURN_OK_IF_SKIP(cctx);
1145 if ((isn = generate_instr(cctx, ISN_NEWDICT)) == NULL) 1143 if ((isn = generate_instr(cctx, ISN_NEWDICT)) == NULL)
1146 return FAIL; 1144 return FAIL;
1147 isn->isn_arg.number = count; 1145 isn->isn_arg.number = count;
1148 1146
1147 member = get_member_type_from_stack(
1148 ((type_T **)stack->ga_data) + stack->ga_len, count, 2,
1149 cctx->ctx_type_list);
1150 type = get_dict_type(member, cctx->ctx_type_list);
1151
1149 // drop the key and value types 1152 // drop the key and value types
1150 stack->ga_len -= 2 * count; 1153 stack->ga_len -= 2 * count;
1151
1152 // Use the first value type for the list member type. Use "void" for an
1153 // empty dict.
1154 if (count > 0)
1155 member = ((type_T **)stack->ga_data)[stack->ga_len + 1];
1156 else
1157 member = &t_void;
1158 type = get_dict_type(member, cctx->ctx_type_list);
1159 1154
1160 // add the dict type to the type stack 1155 // add the dict type to the type stack
1161 if (ga_grow(stack, 1) == FAIL) 1156 if (ga_grow(stack, 1) == FAIL)
1162 return FAIL; 1157 return FAIL;
1163 ((type_T **)stack->ga_data)[stack->ga_len] = type; 1158 ((type_T **)stack->ga_data)[stack->ga_len] = type;