comparison src/list.c @ 25302:4d3c68196d05 v8.2.3188

patch 8.2.3188: Vim9: argument types are not checked at compile time Commit: https://github.com/vim/vim/commit/83494b4ac61898f687d6ef9dce4bad5802fb8e51 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue Jul 20 17:51:51 2021 +0200 patch 8.2.3188: Vim9: argument types are not checked at compile time Problem: Vim9: argument types are not checked at compile time. Solution: Add several more type checks, also at runtime. (Yegappan Lakshmanan, closes #8587)
author Bram Moolenaar <Bram@vim.org>
date Tue, 20 Jul 2021 18:00:06 +0200
parents 8b7ea875afed
children 078edc1821bf
comparison
equal deleted inserted replaced
25301:fe178301fc04 25302:4d3c68196d05
820 flatten_common(typval_T *argvars, typval_T *rettv, int make_copy) 820 flatten_common(typval_T *argvars, typval_T *rettv, int make_copy)
821 { 821 {
822 list_T *l; 822 list_T *l;
823 long maxdepth; 823 long maxdepth;
824 int error = FALSE; 824 int error = FALSE;
825
826 if (in_vim9script()
827 && (check_for_list_arg(argvars, 0) == FAIL
828 || check_for_opt_number_arg(argvars, 1) == FAIL))
829 return;
825 830
826 if (argvars[0].v_type != VAR_LIST) 831 if (argvars[0].v_type != VAR_LIST)
827 { 832 {
828 semsg(_(e_listarg), "flatten()"); 833 semsg(_(e_listarg), "flatten()");
829 return; 834 return;
1265 f_join(typval_T *argvars, typval_T *rettv) 1270 f_join(typval_T *argvars, typval_T *rettv)
1266 { 1271 {
1267 garray_T ga; 1272 garray_T ga;
1268 char_u *sep; 1273 char_u *sep;
1269 1274
1275 if (in_vim9script()
1276 && (check_for_list_arg(argvars, 0) == FAIL
1277 || check_for_opt_string_arg(argvars, 1) == FAIL))
1278 return;
1279
1270 if (argvars[0].v_type != VAR_LIST) 1280 if (argvars[0].v_type != VAR_LIST)
1271 { 1281 {
1272 emsg(_(e_listreq)); 1282 emsg(_(e_listreq));
1273 return; 1283 return;
1274 } 1284 }
1468 garray_T ga; 1478 garray_T ga;
1469 int utf8 = FALSE; 1479 int utf8 = FALSE;
1470 1480
1471 rettv->v_type = VAR_STRING; 1481 rettv->v_type = VAR_STRING;
1472 rettv->vval.v_string = NULL; 1482 rettv->vval.v_string = NULL;
1483
1484 if (in_vim9script()
1485 && (check_for_list_arg(argvars, 0) == FAIL
1486 || check_for_opt_bool_arg(argvars, 1) == FAIL))
1487 return;
1488
1473 if (argvars[0].v_type != VAR_LIST) 1489 if (argvars[0].v_type != VAR_LIST)
1474 { 1490 {
1475 emsg(_(e_invarg)); 1491 emsg(_(e_invarg));
1476 return; 1492 return;
1477 } 1493 }
1519 list_T *l; 1535 list_T *l;
1520 listitem_T *item, *item2; 1536 listitem_T *item, *item2;
1521 listitem_T *li; 1537 listitem_T *li;
1522 int error = FALSE; 1538 int error = FALSE;
1523 long idx; 1539 long idx;
1540
1541 if (in_vim9script()
1542 && (check_for_list_arg(argvars, 0) == FAIL
1543 || check_for_number_arg(argvars, 1) == FAIL
1544 || check_for_opt_number_arg(argvars, 2) == FAIL))
1545 return;
1524 1546
1525 if ((l = argvars[0].vval.v_list) == NULL 1547 if ((l = argvars[0].vval.v_list) == NULL
1526 || value_check_lock(l->lv_lock, arg_errmsg, TRUE)) 1548 || value_check_lock(l->lv_lock, arg_errmsg, TRUE))
1527 return; 1549 return;
1528 1550
2487 { 2509 {
2488 long n = 0; 2510 long n = 0;
2489 int ic = FALSE; 2511 int ic = FALSE;
2490 int error = FALSE; 2512 int error = FALSE;
2491 2513
2514 if (in_vim9script()
2515 && ((argvars[0].v_type != VAR_STRING
2516 && argvars[0].v_type != VAR_LIST
2517 && argvars[0].v_type != VAR_DICT
2518 && check_for_string_arg(argvars, 0) == FAIL)
2519 || check_for_opt_bool_arg(argvars, 2) == FAIL
2520 || (argvars[2].v_type != VAR_UNKNOWN
2521 && check_for_opt_number_arg(argvars, 3) == FAIL)))
2522 return;
2523
2492 if (argvars[2].v_type != VAR_UNKNOWN) 2524 if (argvars[2].v_type != VAR_UNKNOWN)
2493 ic = (int)tv_get_bool_chk(&argvars[2], &error); 2525 ic = (int)tv_get_bool_chk(&argvars[2], &error);
2494 2526
2495 if (argvars[0].v_type == VAR_STRING) 2527 if (argvars[0].v_type == VAR_STRING)
2496 { 2528 {