Mercurial > vim
comparison src/vim9type.c @ 29008:49d8b54802f3 v8.2.5026
patch 8.2.5026: Vim9: a few lines not covered by tests
Commit: https://github.com/vim/vim/commit/31d9948e3a2529c2f619d56bdb48291dc261233d
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu May 26 22:24:43 2022 +0100
patch 8.2.5026: Vim9: a few lines not covered by tests
Problem: Vim9: a few lines not covered by tests.
Solution: Delete dead code. Add a few test cases. make "12->func()" work.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 26 May 2022 23:30:05 +0200 |
parents | ba083decce5d |
children | 9f8dd1b77563 |
comparison
equal
deleted
inserted
replaced
29007:0e8c870971f7 | 29008:49d8b54802f3 |
---|---|
242 return type; | 242 return type; |
243 } | 243 } |
244 | 244 |
245 /* | 245 /* |
246 * Get a function type, based on the return type "ret_type". | 246 * Get a function type, based on the return type "ret_type". |
247 * If "argcount" is -1 or 0 a predefined type can be used. | 247 * "argcount" must be -1 or 0, a predefined type can be used. |
248 * If "argcount" > 0 always create a new type, so that arguments can be added. | |
249 */ | 248 */ |
250 type_T * | 249 type_T * |
251 get_func_type(type_T *ret_type, int argcount, garray_T *type_gap) | 250 get_func_type(type_T *ret_type, int argcount, garray_T *type_gap) |
252 { | 251 { |
253 // recognize commonly used types | 252 // recognize commonly used types |
254 if (argcount <= 0) | 253 if (ret_type == &t_unknown || ret_type == NULL) |
255 { | 254 { |
256 if (ret_type == &t_unknown || ret_type == NULL) | 255 // (argcount == 0) is not possible |
257 { | 256 return &t_func_unknown; |
258 // (argcount == 0) is not possible | 257 } |
259 return &t_func_unknown; | 258 if (ret_type == &t_void) |
260 } | 259 { |
261 if (ret_type == &t_void) | 260 if (argcount == 0) |
262 { | 261 return &t_func_0_void; |
263 if (argcount == 0) | 262 else |
264 return &t_func_0_void; | 263 return &t_func_void; |
265 else | 264 } |
266 return &t_func_void; | 265 if (ret_type == &t_any) |
267 } | 266 { |
268 if (ret_type == &t_any) | 267 if (argcount == 0) |
269 { | 268 return &t_func_0_any; |
270 if (argcount == 0) | 269 else |
271 return &t_func_0_any; | 270 return &t_func_any; |
272 else | 271 } |
273 return &t_func_any; | 272 if (ret_type == &t_number) |
274 } | 273 { |
275 if (ret_type == &t_number) | 274 if (argcount == 0) |
276 { | 275 return &t_func_0_number; |
277 if (argcount == 0) | 276 else |
278 return &t_func_0_number; | 277 return &t_func_number; |
279 else | 278 } |
280 return &t_func_number; | 279 if (ret_type == &t_string) |
281 } | 280 { |
282 if (ret_type == &t_string) | 281 if (argcount == 0) |
283 { | 282 return &t_func_0_string; |
284 if (argcount == 0) | 283 else |
285 return &t_func_0_string; | 284 return &t_func_string; |
286 else | |
287 return &t_func_string; | |
288 } | |
289 } | 285 } |
290 | 286 |
291 return alloc_func_type(ret_type, argcount, type_gap); | 287 return alloc_func_type(ret_type, argcount, type_gap); |
292 } | 288 } |
293 | 289 |
539 type_T * | 535 type_T * |
540 typval2type_vimvar(typval_T *tv, garray_T *type_gap) | 536 typval2type_vimvar(typval_T *tv, garray_T *type_gap) |
541 { | 537 { |
542 if (tv->v_type == VAR_LIST) // e.g. for v:oldfiles | 538 if (tv->v_type == VAR_LIST) // e.g. for v:oldfiles |
543 return &t_list_string; | 539 return &t_list_string; |
544 if (tv->v_type == VAR_DICT) // e.g. for v:completed_item | 540 if (tv->v_type == VAR_DICT) // e.g. for v:event |
545 return &t_dict_any; | 541 return &t_dict_any; |
546 return typval2type(tv, get_copyID(), type_gap, TVTT_DO_MEMBER); | 542 return typval2type(tv, get_copyID(), type_gap, TVTT_DO_MEMBER); |
547 } | 543 } |
548 | 544 |
549 int | 545 int |
1439 */ | 1435 */ |
1440 char * | 1436 char * |
1441 type_name(type_T *type, char **tofree) | 1437 type_name(type_T *type, char **tofree) |
1442 { | 1438 { |
1443 char *name; | 1439 char *name; |
1440 char *arg_free = NULL; | |
1444 | 1441 |
1445 *tofree = NULL; | 1442 *tofree = NULL; |
1446 if (type == NULL) | 1443 if (type == NULL) |
1447 return "[unknown]"; | 1444 return "[unknown]"; |
1448 name = vartype_name(type->tt_type); | 1445 name = vartype_name(type->tt_type); |
1467 int i; | 1464 int i; |
1468 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0; | 1465 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0; |
1469 | 1466 |
1470 ga_init2(&ga, 1, 100); | 1467 ga_init2(&ga, 1, 100); |
1471 if (ga_grow(&ga, 20) == FAIL) | 1468 if (ga_grow(&ga, 20) == FAIL) |
1472 return "[unknown]"; | 1469 goto failed; |
1473 STRCPY(ga.ga_data, "func("); | 1470 STRCPY(ga.ga_data, "func("); |
1474 ga.ga_len += 5; | 1471 ga.ga_len += 5; |
1475 | 1472 |
1476 for (i = 0; i < type->tt_argcount; ++i) | 1473 for (i = 0; i < type->tt_argcount; ++i) |
1477 { | 1474 { |
1478 char *arg_free = NULL; | |
1479 char *arg_type; | 1475 char *arg_type; |
1480 int len; | 1476 int len; |
1481 | 1477 |
1482 if (type->tt_args == NULL) | 1478 if (type->tt_args == NULL) |
1483 arg_type = "[unknown]"; | 1479 arg_type = "[unknown]"; |
1488 STRCPY((char *)ga.ga_data + ga.ga_len, ", "); | 1484 STRCPY((char *)ga.ga_data + ga.ga_len, ", "); |
1489 ga.ga_len += 2; | 1485 ga.ga_len += 2; |
1490 } | 1486 } |
1491 len = (int)STRLEN(arg_type); | 1487 len = (int)STRLEN(arg_type); |
1492 if (ga_grow(&ga, len + 8) == FAIL) | 1488 if (ga_grow(&ga, len + 8) == FAIL) |
1493 { | 1489 goto failed; |
1494 vim_free(arg_free); | |
1495 ga_clear(&ga); | |
1496 return "[unknown]"; | |
1497 } | |
1498 if (varargs && i == type->tt_argcount - 1) | 1490 if (varargs && i == type->tt_argcount - 1) |
1499 ga_concat(&ga, (char_u *)"..."); | 1491 ga_concat(&ga, (char_u *)"..."); |
1500 else if (i >= type->tt_min_argcount) | 1492 else if (i >= type->tt_min_argcount) |
1501 *((char *)ga.ga_data + ga.ga_len++) = '?'; | 1493 *((char *)ga.ga_data + ga.ga_len++) = '?'; |
1502 ga_concat(&ga, (char_u *)arg_type); | 1494 ga_concat(&ga, (char_u *)arg_type); |
1503 vim_free(arg_free); | 1495 VIM_CLEAR(arg_free); |
1504 } | 1496 } |
1505 if (type->tt_argcount < 0) | 1497 if (type->tt_argcount < 0) |
1506 // any number of arguments | 1498 // any number of arguments |
1507 ga_concat(&ga, (char_u *)"..."); | 1499 ga_concat(&ga, (char_u *)"..."); |
1508 | 1500 |
1514 char *ret_name = type_name(type->tt_member, &ret_free); | 1506 char *ret_name = type_name(type->tt_member, &ret_free); |
1515 int len; | 1507 int len; |
1516 | 1508 |
1517 len = (int)STRLEN(ret_name) + 4; | 1509 len = (int)STRLEN(ret_name) + 4; |
1518 if (ga_grow(&ga, len) == FAIL) | 1510 if (ga_grow(&ga, len) == FAIL) |
1519 { | 1511 goto failed; |
1520 vim_free(ret_free); | |
1521 ga_clear(&ga); | |
1522 return "[unknown]"; | |
1523 } | |
1524 STRCPY((char *)ga.ga_data + ga.ga_len, "): "); | 1512 STRCPY((char *)ga.ga_data + ga.ga_len, "): "); |
1525 STRCPY((char *)ga.ga_data + ga.ga_len + 3, ret_name); | 1513 STRCPY((char *)ga.ga_data + ga.ga_len + 3, ret_name); |
1526 vim_free(ret_free); | 1514 vim_free(ret_free); |
1527 } | 1515 } |
1528 *tofree = ga.ga_data; | 1516 *tofree = ga.ga_data; |
1529 return ga.ga_data; | 1517 return ga.ga_data; |
1518 | |
1519 failed: | |
1520 vim_free(arg_free); | |
1521 ga_clear(&ga); | |
1522 return "[unknown]"; | |
1530 } | 1523 } |
1531 | 1524 |
1532 return name; | 1525 return name; |
1533 } | 1526 } |
1534 | 1527 |