To: vim_dev@googlegroups.com Subject: Patch 8.2.0552 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0552 Problem: Vim9: some errors not covered by tests. Solution: Add more tests. Check Funcref argument types. Files: src/vim9compile.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.0551/src/vim9compile.c 2020-04-11 23:17:13.907173700 +0200 --- src/vim9compile.c 2020-04-12 14:36:09.607355407 +0200 *************** *** 1746,1751 **** --- 1746,1753 ---- static int equal_type(type_T *type1, type_T *type2) { + int i; + if (type1->tt_type != type2->tt_type) return FALSE; switch (type1->tt_type) *************** *** 1767,1775 **** return equal_type(type1->tt_member, type2->tt_member); case VAR_FUNC: case VAR_PARTIAL: ! // TODO; check argument types. ! return equal_type(type1->tt_member, type2->tt_member) ! && type1->tt_argcount == type2->tt_argcount; } return TRUE; } --- 1769,1784 ---- return equal_type(type1->tt_member, type2->tt_member); case VAR_FUNC: case VAR_PARTIAL: ! if (!equal_type(type1->tt_member, type2->tt_member) ! || type1->tt_argcount != type2->tt_argcount) ! return FALSE; ! if (type1->tt_argcount < 0 ! || type1->tt_args == NULL || type2->tt_args == NULL) ! return TRUE; ! for (i = 0; i < type1->tt_argcount; ++i) ! if (!equal_type(type1->tt_args[i], type2->tt_args[i])) ! return FALSE; ! return TRUE; } return TRUE; } *************** *** 1800,1807 **** *dest = get_dict_type(common, type_gap); return; } ! // TODO: VAR_FUNC and VAR_PARTIAL ! *dest = type1; } *dest = &t_any; --- 1809,1839 ---- *dest = get_dict_type(common, type_gap); return; } ! if (type1->tt_type == VAR_FUNC) ! { ! type_T *common; ! ! common_type(type1->tt_member, type2->tt_member, &common, type_gap); ! if (type1->tt_argcount == type2->tt_argcount ! && type1->tt_argcount >= 0) ! { ! int argcount = type1->tt_argcount; ! int i; ! ! *dest = alloc_func_type(common, argcount, type_gap); ! if (type1->tt_args != NULL && type2->tt_args != NULL) ! { ! (*dest)->tt_args = ALLOC_CLEAR_MULT(type_T *, argcount); ! if ((*dest)->tt_args != NULL) ! for (i = 0; i < argcount; ++i) ! common_type(type1->tt_args[i], type2->tt_args[i], ! &(*dest)->tt_args[i], type_gap); ! } ! } ! else ! *dest = alloc_func_type(common, -1, type_gap); ! return; ! } } *dest = &t_any; *** ../vim-8.2.0551/src/testdir/test_vim9_func.vim 2020-04-11 23:17:13.907173700 +0200 --- src/testdir/test_vim9_func.vim 2020-04-12 14:28:17.960748446 +0200 *************** *** 96,101 **** --- 96,102 ---- assert_fails('call MyDefaultArgs("one", "two")', 'E118:') call CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef'], 'E1001:') + call CheckScriptFailure(['def Func(arg: number = "text")', 'enddef'], 'E1013: argument 1: type mismatch, expected number but got string') enddef func Test_call_default_args_from_func() *************** *** 196,201 **** --- 197,222 ---- call assert_fails('call NotDefined("one")', 'E117:') enddef + def CombineFuncrefTypes() + " same arguments, different return type + let Ref1: func(bool): string + let Ref2: func(bool): number + let Ref3: func(bool): any + Ref3 = g:cond ? Ref1 : Ref2 + + " different number of arguments + let Refa1: func(bool): number + let Refa2: func(bool, number): number + let Refa3: func: number + Refa3 = g:cond ? Refa1 : Refa2 + + " different argument types + let Refb1: func(bool, string): number + let Refb2: func(string, number): number + let Refb3: func(any, any): number + Refb3 = g:cond ? Refb1 : Refb2 + enddef + func DefinedLater(arg) return a:arg endfunc *** ../vim-8.2.0551/src/version.c 2020-04-12 13:50:22.832171856 +0200 --- src/version.c 2020-04-12 14:08:02.981119988 +0200 *************** *** 740,741 **** --- 740,743 ---- { /* Add new patch number below this line */ + /**/ + 552, /**/ -- FATAL ERROR! SYSTEM HALTED! - Press any key to continue doing nothing. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///