comparison src/vim9instr.c @ 27503:4cea92e99a5a v8.2.4279

patch 8.2.4279: Vim9: cannot change item type with map() after range() Commit: https://github.com/vim/vim/commit/8133018f50bc447570825801e93d5ed67e8dac90 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Feb 1 12:11:58 2022 +0000 patch 8.2.4279: Vim9: cannot change item type with map() after range() Problem: Vim9: cannot change item type with map() after range(). Solution: Split the return type in current type and declared type. (closes #9665)
author Bram Moolenaar <Bram@vim.org>
date Tue, 01 Feb 2022 13:15:03 +0100
parents 4c1bdee75bed
children 5bf2fca4f967
comparison
equal deleted inserted replaced
27502:aad2a09123be 27503:4cea92e99a5a
1076 return FAIL; 1076 return FAIL;
1077 isn->isn_arg.number = count; 1077 isn->isn_arg.number = count;
1078 1078
1079 // Get the member type and the declared member type from all the items on 1079 // Get the member type and the declared member type from all the items on
1080 // the stack. 1080 // the stack.
1081 member_type = get_member_type_from_stack(count, 1, &decl_member_type, cctx); 1081 member_type = get_member_type_from_stack(count, 1,
1082 &decl_member_type, cctx);
1082 type = get_list_type(member_type, cctx->ctx_type_list); 1083 type = get_list_type(member_type, cctx->ctx_type_list);
1083 decl_type = get_list_type(decl_member_type, cctx->ctx_type_list); 1084 decl_type = get_list_type(decl_member_type, cctx->ctx_type_list);
1084 1085
1085 // drop the value types 1086 // drop the value types
1086 cctx->ctx_type_stack.ga_len -= count; 1087 cctx->ctx_type_stack.ga_len -= count;
1275 type2_T *typep; 1276 type2_T *typep;
1276 type2_T *argtypes = NULL; 1277 type2_T *argtypes = NULL;
1277 type2_T shuffled_argtypes[MAX_FUNC_ARGS]; 1278 type2_T shuffled_argtypes[MAX_FUNC_ARGS];
1278 type2_T *maptype = NULL; 1279 type2_T *maptype = NULL;
1279 type_T *type; 1280 type_T *type;
1281 type_T *decl_type;
1280 1282
1281 RETURN_OK_IF_SKIP(cctx); 1283 RETURN_OK_IF_SKIP(cctx);
1282 argoff = check_internal_func(func_idx, argcount); 1284 argoff = check_internal_func(func_idx, argcount);
1283 if (argoff < 0) 1285 if (argoff < 0)
1284 return FAIL; 1286 return FAIL;
1325 isn->isn_arg.bfunc.cbf_idx = func_idx; 1327 isn->isn_arg.bfunc.cbf_idx = func_idx;
1326 isn->isn_arg.bfunc.cbf_argcount = argcount; 1328 isn->isn_arg.bfunc.cbf_argcount = argcount;
1327 1329
1328 // Drop the argument types and push the return type. 1330 // Drop the argument types and push the return type.
1329 stack->ga_len -= argcount; 1331 stack->ga_len -= argcount;
1330 type = internal_func_ret_type(func_idx, argcount, argtypes); 1332 type = internal_func_ret_type(func_idx, argcount, argtypes, &decl_type);
1331 if (push_type_stack(cctx, type) == FAIL) 1333 if (push_type_stack2(cctx, type, decl_type) == FAIL)
1332 return FAIL; 1334 return FAIL;
1333 1335
1334 if (maptype != NULL && maptype[0].type_decl->tt_member != NULL 1336 if (maptype != NULL && maptype[0].type_decl->tt_member != NULL
1335 && maptype[0].type_decl->tt_member != &t_any) 1337 && maptype[0].type_decl->tt_member != &t_any)
1336 // Check that map() didn't change the item types. 1338 // Check that map() didn't change the item types.
1349 type_T *list_type; 1351 type_T *list_type;
1350 type_T *item_type; 1352 type_T *item_type;
1351 type_T *expected; 1353 type_T *expected;
1352 1354
1353 // Caller already checked that list_type is a list. 1355 // Caller already checked that list_type is a list.
1354 list_type = get_type_on_stack(cctx, 1); 1356 // For checking the item type we use the declared type of the list and the
1357 // current type of the added item, adding a string to [1, 2] is OK.
1358 list_type = get_decl_type_on_stack(cctx, 1);
1355 item_type = get_type_on_stack(cctx, 0); 1359 item_type = get_type_on_stack(cctx, 0);
1356 expected = list_type->tt_member; 1360 expected = list_type->tt_member;
1357 if (need_type(item_type, expected, -1, 0, cctx, FALSE, FALSE) == FAIL) 1361 if (need_type(item_type, expected, -1, 0, cctx, FALSE, FALSE) == FAIL)
1358 return FAIL; 1362 return FAIL;
1359 1363