comparison src/vim9type.c @ 25126:b825efff9790 v8.2.3100

patch 8.2.3100: Vim9: no error when using type with unknown number of args Commit: https://github.com/vim/vim/commit/7a40ff00edd35cc4313d74a43e7a7b67cd24372d Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 4 15:54:08 2021 +0200 patch 8.2.3100: Vim9: no error when using type with unknown number of args Problem: Vim9: no error when using type with unknown number of arguments. Solution: Do not ignore argument count of -1. (closes https://github.com/vim/vim/issues/8492)
author Bram Moolenaar <Bram@vim.org>
date Sun, 04 Jul 2021 16:00:03 +0200
parents 0136c6ee1961
children 5731bcaaabcb
comparison
equal deleted inserted replaced
25125:a3ab834c714c 25126:b825efff9790
258 typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member) 258 typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
259 { 259 {
260 type_T *type; 260 type_T *type;
261 type_T *member_type = &t_any; 261 type_T *member_type = &t_any;
262 int argcount = 0; 262 int argcount = 0;
263 int min_argcount = 0;
263 264
264 if (tv->v_type == VAR_NUMBER) 265 if (tv->v_type == VAR_NUMBER)
265 return &t_number; 266 return &t_number;
266 if (tv->v_type == VAR_BOOL) 267 if (tv->v_type == VAR_BOOL)
267 return &t_bool; 268 return &t_bool;
335 { 336 {
336 int idx = find_internal_func(name); 337 int idx = find_internal_func(name);
337 338
338 if (idx >= 0) 339 if (idx >= 0)
339 { 340 {
340 // TODO: get actual arg count and types 341 internal_func_get_argcount(idx, &argcount, &min_argcount);
341 argcount = -1;
342 member_type = internal_func_ret_type(idx, 0, NULL); 342 member_type = internal_func_ret_type(idx, 0, NULL);
343 } 343 }
344 else 344 else
345 ufunc = find_func(name, FALSE, NULL); 345 ufunc = find_func(name, FALSE, NULL);
346 } 346 }
362 type = get_type_ptr(type_gap); 362 type = get_type_ptr(type_gap);
363 if (type == NULL) 363 if (type == NULL)
364 return NULL; 364 return NULL;
365 type->tt_type = tv->v_type; 365 type->tt_type = tv->v_type;
366 type->tt_argcount = argcount; 366 type->tt_argcount = argcount;
367 type->tt_min_argcount = min_argcount;
367 type->tt_member = member_type; 368 type->tt_member = member_type;
368 369
369 return type; 370 return type;
370 } 371 }
371 372
523 if (expected->tt_member != &t_unknown 524 if (expected->tt_member != &t_unknown
524 && actual->tt_member != &t_unknown) 525 && actual->tt_member != &t_unknown)
525 ret = check_type(expected->tt_member, actual->tt_member, 526 ret = check_type(expected->tt_member, actual->tt_member,
526 FALSE, where); 527 FALSE, where);
527 if (ret == OK && expected->tt_argcount != -1 528 if (ret == OK && expected->tt_argcount != -1
528 && actual->tt_argcount != -1 529 && (actual->tt_argcount == -1
529 && (actual->tt_argcount < expected->tt_min_argcount 530 || (actual->tt_argcount < expected->tt_min_argcount
530 || actual->tt_argcount > expected->tt_argcount)) 531 || actual->tt_argcount > expected->tt_argcount)))
531 ret = FAIL; 532 ret = FAIL;
532 if (ret == OK && expected->tt_args != NULL 533 if (ret == OK && expected->tt_args != NULL
533 && actual->tt_args != NULL) 534 && actual->tt_args != NULL)
534 { 535 {
535 int i; 536 int i;
1030 common_type(type1->tt_args[i], type2->tt_args[i], 1031 common_type(type1->tt_args[i], type2->tt_args[i],
1031 &(*dest)->tt_args[i], type_gap); 1032 &(*dest)->tt_args[i], type_gap);
1032 } 1033 }
1033 } 1034 }
1034 else 1035 else
1036 // Use -1 for "tt_argcount" to indicate an unknown number of
1037 // arguments.
1035 *dest = alloc_func_type(common, -1, type_gap); 1038 *dest = alloc_func_type(common, -1, type_gap);
1039
1036 // Use the minimum of min_argcount. 1040 // Use the minimum of min_argcount.
1037 (*dest)->tt_min_argcount = 1041 (*dest)->tt_min_argcount =
1038 type1->tt_min_argcount < type2->tt_min_argcount 1042 type1->tt_min_argcount < type2->tt_min_argcount
1039 ? type1->tt_min_argcount : type2->tt_min_argcount; 1043 ? type1->tt_min_argcount : type2->tt_min_argcount;
1040 return; 1044 return;