comparison src/vim9type.c @ 31698:9fba3e8bbadc v9.0.1181

patch 9.0.1181: class inheritance and typing insufficiently tested Commit: https://github.com/vim/vim/commit/6481accd4086845cfce7548e06cb797c80587a98 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 11 21:14:17 2023 +0000 patch 9.0.1181: class inheritance and typing insufficiently tested Problem: Class inheritance and typing insufficiently tested. Solution: Add more tests. Implement missing behavior.
author Bram Moolenaar <Bram@vim.org>
date Wed, 11 Jan 2023 22:15:02 +0100
parents b6044f37d53d
children 69ee530cac28
comparison
equal deleted inserted replaced
31697:5b7ae9350da9 31698:9fba3e8bbadc
872 if (ret == OK && expected->tt_argcount >= 0 872 if (ret == OK && expected->tt_argcount >= 0
873 && actual->tt_argcount == -1) 873 && actual->tt_argcount == -1)
874 // check the argument count at runtime 874 // check the argument count at runtime
875 ret = MAYBE; 875 ret = MAYBE;
876 } 876 }
877 else if (expected->tt_type == VAR_OBJECT)
878 {
879 class_T *cl;
880 for (cl = (class_T *)actual->tt_member; cl != NULL;
881 cl = cl->class_extends)
882 if ((class_T *)expected->tt_member == cl)
883 break;
884 if (cl == NULL)
885 ret = FAIL;
886 }
887
877 if (ret == FAIL && give_msg) 888 if (ret == FAIL && give_msg)
878 type_mismatch_where(expected, actual, where); 889 type_mismatch_where(expected, actual, where);
879 } 890 }
880 891
881 if (ret == OK && expected->tt_type != VAR_UNKNOWN 892 if (ret == OK && expected->tt_type != VAR_UNKNOWN
1599 1610
1600 *tofree = NULL; 1611 *tofree = NULL;
1601 if (type == NULL) 1612 if (type == NULL)
1602 return "[unknown]"; 1613 return "[unknown]";
1603 name = vartype_name(type->tt_type); 1614 name = vartype_name(type->tt_type);
1615
1604 if (type->tt_type == VAR_LIST || type->tt_type == VAR_DICT) 1616 if (type->tt_type == VAR_LIST || type->tt_type == VAR_DICT)
1605 { 1617 {
1606 char *member_free; 1618 char *member_free;
1607 char *member_name = type_name(type->tt_member, &member_free); 1619 char *member_name = type_name(type->tt_member, &member_free);
1608 size_t len; 1620 size_t len = STRLEN(name) + STRLEN(member_name) + 3;
1609
1610 len = STRLEN(name) + STRLEN(member_name) + 3;
1611 *tofree = alloc(len); 1621 *tofree = alloc(len);
1612 if (*tofree != NULL) 1622 if (*tofree != NULL)
1613 { 1623 {
1614 vim_snprintf(*tofree, len, "%s<%s>", name, member_name); 1624 vim_snprintf(*tofree, len, "%s<%s>", name, member_name);
1615 vim_free(member_free); 1625 vim_free(member_free);
1616 return *tofree; 1626 return *tofree;
1617 } 1627 }
1618 } 1628 }
1629
1630 if (type->tt_type == VAR_OBJECT || type->tt_type == VAR_CLASS)
1631 {
1632 char_u *class_name = ((class_T *)type->tt_member)->class_name;
1633 size_t len = STRLEN(name) + STRLEN(class_name) + 3;
1634 *tofree = alloc(len);
1635 if (*tofree != NULL)
1636 {
1637 vim_snprintf(*tofree, len, "%s<%s>", name, class_name);
1638 return *tofree;
1639 }
1640 }
1641
1619 if (type->tt_type == VAR_FUNC) 1642 if (type->tt_type == VAR_FUNC)
1620 { 1643 {
1621 garray_T ga; 1644 garray_T ga;
1622 int i; 1645 int i;
1623 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0; 1646 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0;