comparison src/evalfunc.c @ 27392:ec2ba9acec1b v8.2.4224

patch 8.2.4224: Vim9: no error when using a number for map() second argument Commit: https://github.com/vim/vim/commit/1080c48ec8d672d7e9fbefb5a1255c9df09a2884 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 26 18:26:21 2022 +0000 patch 8.2.4224: Vim9: no error when using a number for map() second argument Problem: Vim9: no error when using a number for map() second argument Solution: Disallow number to string conversion. (closes https://github.com/vim/vim/issues/9630)
author Bram Moolenaar <Bram@vim.org>
date Wed, 26 Jan 2022 19:30:03 +0100
parents 69aa20a6e7ae
children 69a48bcd1d80
comparison
equal deleted inserted replaced
27391:5854ea4dc132 27392:ec2ba9acec1b
489 * Check second argument of filter(): func must return a bool. 489 * Check second argument of filter(): func must return a bool.
490 */ 490 */
491 static int 491 static int
492 arg_filter_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context) 492 arg_filter_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context)
493 { 493 {
494 if (type->tt_type == VAR_FUNC 494 if (type->tt_type == VAR_STRING
495 && !(type->tt_member->tt_type == VAR_BOOL 495 || type->tt_type == VAR_PARTIAL
496 || type == &t_unknown
497 || type == &t_any)
498 return OK;
499
500 if (type->tt_type == VAR_FUNC)
501 {
502 if (!(type->tt_member->tt_type == VAR_BOOL
496 || type->tt_member->tt_type == VAR_NUMBER 503 || type->tt_member->tt_type == VAR_NUMBER
497 || type->tt_member->tt_type == VAR_UNKNOWN 504 || type->tt_member->tt_type == VAR_UNKNOWN
498 || type->tt_member->tt_type == VAR_ANY)) 505 || type->tt_member->tt_type == VAR_ANY))
499 { 506 {
500 arg_type_mismatch(&t_func_bool, type, context->arg_idx + 1); 507 arg_type_mismatch(&t_func_bool, type, context->arg_idx + 1);
508 return FAIL;
509 }
510 }
511 else
512 {
513 semsg(_(e_string_or_function_required_for_argument_nr), 2);
501 return FAIL; 514 return FAIL;
502 } 515 }
503 return OK; 516 return OK;
504 } 517 }
505 518
507 * Check second argument of map(). 520 * Check second argument of map().
508 */ 521 */
509 static int 522 static int
510 arg_map_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context) 523 arg_map_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context)
511 { 524 {
512 if (type->tt_type == VAR_FUNC 525 if (type->tt_type == VAR_STRING
513 && type->tt_member != &t_any 526 || type->tt_type == VAR_PARTIAL
527 || type == &t_unknown
528 || type == &t_any)
529 return OK;
530
531 if (type->tt_type == VAR_FUNC)
532 {
533 if (type->tt_member != &t_any
514 && type->tt_member != &t_unknown) 534 && type->tt_member != &t_unknown)
515 {
516 type_T *expected = NULL;
517
518 if (context->arg_types[0].type_curr->tt_type == VAR_LIST
519 || context->arg_types[0].type_curr->tt_type == VAR_DICT)
520 expected = context->arg_types[0].type_curr->tt_member;
521 else if (context->arg_types[0].type_curr->tt_type == VAR_STRING)
522 expected = &t_string;
523 else if (context->arg_types[0].type_curr->tt_type == VAR_BLOB)
524 expected = &t_number;
525 if (expected != NULL)
526 { 535 {
527 type_T t_func_exp = {VAR_FUNC, -1, 0, TTFLAG_STATIC, NULL, NULL}; 536 type_T *expected = NULL;
528 537
529 t_func_exp.tt_member = expected; 538 if (context->arg_types[0].type_curr->tt_type == VAR_LIST
530 return check_arg_type(&t_func_exp, type, context); 539 || context->arg_types[0].type_curr->tt_type == VAR_DICT)
540 expected = context->arg_types[0].type_curr->tt_member;
541 else if (context->arg_types[0].type_curr->tt_type == VAR_STRING)
542 expected = &t_string;
543 else if (context->arg_types[0].type_curr->tt_type == VAR_BLOB)
544 expected = &t_number;
545 if (expected != NULL)
546 {
547 type_T t_func_exp = {VAR_FUNC, -1, 0, TTFLAG_STATIC, NULL, NULL};
548
549 t_func_exp.tt_member = expected;
550 return check_arg_type(&t_func_exp, type, context);
551 }
531 } 552 }
553 }
554 else
555 {
556 semsg(_(e_string_or_function_required_for_argument_nr), 2);
557 return FAIL;
532 } 558 }
533 return OK; 559 return OK;
534 } 560 }
535 561
536 /* 562 /*