Mercurial > vim
comparison src/vim9compile.c @ 21383:f25d007f90ac v8.2.1242
patch 8.2.1242: Vim9: no error if calling a function with wrong type
Commit: https://github.com/vim/vim/commit/65b9545f4494abcb455400c08e51de27bc305866
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 19 14:03:09 2020 +0200
patch 8.2.1242: Vim9: no error if calling a function with wrong type
Problem: Vim9: no error if calling a function with wrong argument type.
Solution: Check types of arguments. (closes https://github.com/vim/vim/issues/6469)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 19 Jul 2020 14:15:04 +0200 |
parents | 8e1081ede3b8 |
children | 54a304e4dc57 |
comparison
equal
deleted
inserted
replaced
21382:22083c0131d2 | 21383:f25d007f90ac |
---|---|
557 if (ret == FAIL && give_msg) | 557 if (ret == FAIL && give_msg) |
558 type_mismatch(expected, actual); | 558 type_mismatch(expected, actual); |
559 } | 559 } |
560 return ret; | 560 return ret; |
561 } | 561 } |
562 | |
563 /* | |
564 * Return FAIl if "expected" and "actual" don't match. | |
565 * TODO: better type comparison | |
566 */ | |
567 int | |
568 check_argtype(type_T *expected, typval_T *actual_tv) | |
569 { | |
570 type_T actual; | |
571 type_T member; | |
572 | |
573 // TODO: should should be done with more levels | |
574 CLEAR_FIELD(actual); | |
575 actual.tt_type = actual_tv->v_type; | |
576 if (actual_tv->v_type == VAR_LIST | |
577 && actual_tv->vval.v_list != NULL | |
578 && actual_tv->vval.v_list->lv_first != NULL) | |
579 { | |
580 // Use the type of the first member, it is the most specific. | |
581 CLEAR_FIELD(member); | |
582 member.tt_type = actual_tv->vval.v_list->lv_first->li_tv.v_type; | |
583 member.tt_member = &t_any; | |
584 actual.tt_member = &member; | |
585 } | |
586 else if (actual_tv->v_type == VAR_DICT | |
587 && actual_tv->vval.v_dict != NULL | |
588 && actual_tv->vval.v_dict->dv_hashtab.ht_used > 0) | |
589 { | |
590 dict_iterator_T iter; | |
591 typval_T *value; | |
592 | |
593 // Use the type of the first value, it is the most specific. | |
594 dict_iterate_start(actual_tv, &iter); | |
595 dict_iterate_next(&iter, &value); | |
596 CLEAR_FIELD(member); | |
597 member.tt_type = value->v_type; | |
598 member.tt_member = &t_any; | |
599 actual.tt_member = &member; | |
600 } | |
601 else | |
602 actual.tt_member = &t_any; | |
603 return check_type(expected, &actual, TRUE); | |
604 } | |
605 | |
562 | 606 |
563 ///////////////////////////////////////////////////////////////////// | 607 ///////////////////////////////////////////////////////////////////// |
564 // Following generate_ functions expect the caller to call ga_grow(). | 608 // Following generate_ functions expect the caller to call ga_grow(). |
565 | 609 |
566 #define RETURN_NULL_IF_SKIP(cctx) if (cctx->ctx_skip == SKIP_YES) return NULL | 610 #define RETURN_NULL_IF_SKIP(cctx) if (cctx->ctx_skip == SKIP_YES) return NULL |