comparison src/vim9compile.c @ 19579:aae19dd172c0 v8.2.0346

patch 8.2.0346: Vim9: finding common list type not tested Commit: https://github.com/vim/vim/commit/61a6d4e48b4778bdbc741af8ac59519b70f65db8 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 1 23:32:25 2020 +0100 patch 8.2.0346: Vim9: finding common list type not tested Problem: Vim9: finding common list type not tested. Solution: Add more tests. Fix listing function. Fix overwriting type.
author Bram Moolenaar <Bram@vim.org>
date Sun, 01 Mar 2020 23:45:04 +0100
parents 6b6e97d0185e
children ba35daca6553
comparison
equal deleted inserted replaced
19578:0ed88fd84485 19579:aae19dd172c0
1441 case VAR_FLOAT: 1441 case VAR_FLOAT:
1442 case VAR_STRING: 1442 case VAR_STRING:
1443 case VAR_BLOB: 1443 case VAR_BLOB:
1444 case VAR_JOB: 1444 case VAR_JOB:
1445 case VAR_CHANNEL: 1445 case VAR_CHANNEL:
1446 return TRUE; // not composite is always OK 1446 break; // not composite is always OK
1447 case VAR_LIST: 1447 case VAR_LIST:
1448 case VAR_DICT: 1448 case VAR_DICT:
1449 return equal_type(type1->tt_member, type2->tt_member); 1449 return equal_type(type1->tt_member, type2->tt_member);
1450 case VAR_FUNC: 1450 case VAR_FUNC:
1451 case VAR_PARTIAL: 1451 case VAR_PARTIAL:
1459 /* 1459 /*
1460 * Find the common type of "type1" and "type2" and put it in "dest". 1460 * Find the common type of "type1" and "type2" and put it in "dest".
1461 * "type2" and "dest" may be the same. 1461 * "type2" and "dest" may be the same.
1462 */ 1462 */
1463 static void 1463 static void
1464 common_type(type_T *type1, type_T *type2, type_T *dest) 1464 common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_list)
1465 { 1465 {
1466 if (equal_type(type1, type2)) 1466 if (equal_type(type1, type2))
1467 { 1467 {
1468 if (dest != type2) 1468 *dest = type1;
1469 *dest = *type2;
1470 return; 1469 return;
1471 } 1470 }
1472 1471
1473 if (type1->tt_type == type2->tt_type) 1472 if (type1->tt_type == type2->tt_type)
1474 { 1473 {
1475 dest->tt_type = type1->tt_type;
1476 if (type1->tt_type == VAR_LIST || type2->tt_type == VAR_DICT) 1474 if (type1->tt_type == VAR_LIST || type2->tt_type == VAR_DICT)
1477 { 1475 {
1478 common_type(type1->tt_member, type2->tt_member, dest->tt_member); 1476 type_T *common;
1477
1478 common_type(type1->tt_member, type2->tt_member, &common, type_list);
1479 if (type1->tt_type == VAR_LIST)
1480 *dest = get_list_type(common, type_list);
1481 else
1482 *dest = get_dict_type(common, type_list);
1479 return; 1483 return;
1480 } 1484 }
1481 // TODO: VAR_FUNC and VAR_PARTIAL 1485 // TODO: VAR_FUNC and VAR_PARTIAL
1482 } 1486 *dest = type1;
1483 1487 }
1484 dest->tt_type = VAR_UNKNOWN; // "any" 1488
1489 *dest = &t_any;
1485 } 1490 }
1486 1491
1487 char * 1492 char *
1488 vartype_name(vartype_T type) 1493 vartype_name(vartype_T type)
1489 { 1494 {
1499 case VAR_BLOB: return "blob"; 1504 case VAR_BLOB: return "blob";
1500 case VAR_JOB: return "job"; 1505 case VAR_JOB: return "job";
1501 case VAR_CHANNEL: return "channel"; 1506 case VAR_CHANNEL: return "channel";
1502 case VAR_LIST: return "list"; 1507 case VAR_LIST: return "list";
1503 case VAR_DICT: return "dict"; 1508 case VAR_DICT: return "dict";
1504 case VAR_FUNC: return "function"; 1509 case VAR_FUNC: return "func";
1505 case VAR_PARTIAL: return "partial"; 1510 case VAR_PARTIAL: return "partial";
1506 } 1511 }
1507 return "???"; 1512 return "???";
1508 } 1513 }
1509 1514
3158 if (compile_expr1(arg, cctx) == FAIL) 3163 if (compile_expr1(arg, cctx) == FAIL)
3159 return FAIL; 3164 return FAIL;
3160 3165
3161 // If the types differ, the result has a more generic type. 3166 // If the types differ, the result has a more generic type.
3162 type2 = ((type_T **)stack->ga_data)[stack->ga_len - 1]; 3167 type2 = ((type_T **)stack->ga_data)[stack->ga_len - 1];
3163 common_type(type1, type2, type2); 3168 common_type(type1, type2, &type2, cctx->ctx_type_list);
3164 3169
3165 // jump here from JUMP_ALWAYS 3170 // jump here from JUMP_ALWAYS
3166 isn = ((isn_T *)instr->ga_data) + end_idx; 3171 isn = ((isn_T *)instr->ga_data) + end_idx;
3167 isn->isn_arg.jump.jump_where = instr->ga_len; 3172 isn->isn_arg.jump.jump_where = instr->ga_len;
3168 } 3173 }