comparison src/vim9compile.c @ 19993:efe864a7ce4f v8.2.0552

patch 8.2.0552: Vim9: some errors not covered by tests Commit: https://github.com/vim/vim/commit/99aaf0ce7cc23b0e759eab2369e266cdc8d46af8 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 12 14:39:53 2020 +0200 patch 8.2.0552: Vim9: some errors not covered by tests Problem: Vim9: some errors not covered by tests. Solution: Add more tests. Check Funcref argument types.
author Bram Moolenaar <Bram@vim.org>
date Sun, 12 Apr 2020 14:45:04 +0200
parents f863aa96cae5
children 844c7646f61b
comparison
equal deleted inserted replaced
19992:6dad0fd5b8e6 19993:efe864a7ce4f
1744 * Check if "type1" and "type2" are exactly the same. 1744 * Check if "type1" and "type2" are exactly the same.
1745 */ 1745 */
1746 static int 1746 static int
1747 equal_type(type_T *type1, type_T *type2) 1747 equal_type(type_T *type1, type_T *type2)
1748 { 1748 {
1749 int i;
1750
1749 if (type1->tt_type != type2->tt_type) 1751 if (type1->tt_type != type2->tt_type)
1750 return FALSE; 1752 return FALSE;
1751 switch (type1->tt_type) 1753 switch (type1->tt_type)
1752 { 1754 {
1753 case VAR_UNKNOWN: 1755 case VAR_UNKNOWN:
1765 case VAR_LIST: 1767 case VAR_LIST:
1766 case VAR_DICT: 1768 case VAR_DICT:
1767 return equal_type(type1->tt_member, type2->tt_member); 1769 return equal_type(type1->tt_member, type2->tt_member);
1768 case VAR_FUNC: 1770 case VAR_FUNC:
1769 case VAR_PARTIAL: 1771 case VAR_PARTIAL:
1770 // TODO; check argument types. 1772 if (!equal_type(type1->tt_member, type2->tt_member)
1771 return equal_type(type1->tt_member, type2->tt_member) 1773 || type1->tt_argcount != type2->tt_argcount)
1772 && type1->tt_argcount == type2->tt_argcount; 1774 return FALSE;
1775 if (type1->tt_argcount < 0
1776 || type1->tt_args == NULL || type2->tt_args == NULL)
1777 return TRUE;
1778 for (i = 0; i < type1->tt_argcount; ++i)
1779 if (!equal_type(type1->tt_args[i], type2->tt_args[i]))
1780 return FALSE;
1781 return TRUE;
1773 } 1782 }
1774 return TRUE; 1783 return TRUE;
1775 } 1784 }
1776 1785
1777 /* 1786 /*
1798 *dest = get_list_type(common, type_gap); 1807 *dest = get_list_type(common, type_gap);
1799 else 1808 else
1800 *dest = get_dict_type(common, type_gap); 1809 *dest = get_dict_type(common, type_gap);
1801 return; 1810 return;
1802 } 1811 }
1803 // TODO: VAR_FUNC and VAR_PARTIAL 1812 if (type1->tt_type == VAR_FUNC)
1804 *dest = type1; 1813 {
1814 type_T *common;
1815
1816 common_type(type1->tt_member, type2->tt_member, &common, type_gap);
1817 if (type1->tt_argcount == type2->tt_argcount
1818 && type1->tt_argcount >= 0)
1819 {
1820 int argcount = type1->tt_argcount;
1821 int i;
1822
1823 *dest = alloc_func_type(common, argcount, type_gap);
1824 if (type1->tt_args != NULL && type2->tt_args != NULL)
1825 {
1826 (*dest)->tt_args = ALLOC_CLEAR_MULT(type_T *, argcount);
1827 if ((*dest)->tt_args != NULL)
1828 for (i = 0; i < argcount; ++i)
1829 common_type(type1->tt_args[i], type2->tt_args[i],
1830 &(*dest)->tt_args[i], type_gap);
1831 }
1832 }
1833 else
1834 *dest = alloc_func_type(common, -1, type_gap);
1835 return;
1836 }
1805 } 1837 }
1806 1838
1807 *dest = &t_any; 1839 *dest = &t_any;
1808 } 1840 }
1809 1841