To: vim_dev@googlegroups.com Subject: Patch 8.2.3100 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3100 Problem: Vim9: no error when using type with unknown number of arguments. Solution: Do not ignore argument count of -1. (closes #8492) Files: src/vim9type.c, src/evalfunc.c, src/proto/evalfunc.pro, src/testdir/test_vim9_assign.vim, src/testdir/test_vim9_expr.vim, src/testdir/test_vim9_func.vim *** ../vim-8.2.3099/src/vim9type.c 2021-06-22 19:32:13.356374012 +0200 --- src/vim9type.c 2021-07-04 15:45:21.840794416 +0200 *************** *** 260,265 **** --- 260,266 ---- type_T *type; type_T *member_type = &t_any; int argcount = 0; + int min_argcount = 0; if (tv->v_type == VAR_NUMBER) return &t_number; *************** *** 337,344 **** if (idx >= 0) { ! // TODO: get actual arg count and types ! argcount = -1; member_type = internal_func_ret_type(idx, 0, NULL); } else --- 338,344 ---- if (idx >= 0) { ! internal_func_get_argcount(idx, &argcount, &min_argcount); member_type = internal_func_ret_type(idx, 0, NULL); } else *************** *** 364,369 **** --- 364,370 ---- return NULL; type->tt_type = tv->v_type; type->tt_argcount = argcount; + type->tt_min_argcount = min_argcount; type->tt_member = member_type; return type; *************** *** 525,533 **** ret = check_type(expected->tt_member, actual->tt_member, FALSE, where); if (ret == OK && expected->tt_argcount != -1 ! && actual->tt_argcount != -1 ! && (actual->tt_argcount < expected->tt_min_argcount ! || actual->tt_argcount > expected->tt_argcount)) ret = FAIL; if (ret == OK && expected->tt_args != NULL && actual->tt_args != NULL) --- 526,534 ---- ret = check_type(expected->tt_member, actual->tt_member, FALSE, where); if (ret == OK && expected->tt_argcount != -1 ! && (actual->tt_argcount == -1 ! || (actual->tt_argcount < expected->tt_min_argcount ! || actual->tt_argcount > expected->tt_argcount))) ret = FAIL; if (ret == OK && expected->tt_args != NULL && actual->tt_args != NULL) *************** *** 1032,1038 **** --- 1033,1042 ---- } } else + // Use -1 for "tt_argcount" to indicate an unknown number of + // arguments. *dest = alloc_func_type(common, -1, type_gap); + // Use the minimum of min_argcount. (*dest)->tt_min_argcount = type1->tt_min_argcount < type2->tt_min_argcount *** ../vim-8.2.3099/src/evalfunc.c 2021-07-03 11:58:08.373825923 +0200 --- src/evalfunc.c 2021-07-04 15:45:23.344791416 +0200 *************** *** 2055,2060 **** --- 2055,2072 ---- } /* + * Get the argument count for function "idx". + * "argcount" is the total argument count, "min_argcount" the non-optional + * argument count. + */ + void + internal_func_get_argcount(int idx, int *argcount, int *min_argcount) + { + *argcount = global_functions[idx].f_max_argc; + *min_argcount = global_functions[idx].f_min_argc; + } + + /* * Call the "f_retfunc" function to obtain the return type of function "idx". * "argtypes" is the list of argument types or NULL when there are no * arguments. *** ../vim-8.2.3099/src/proto/evalfunc.pro 2021-06-02 14:56:35.823997065 +0200 --- src/proto/evalfunc.pro 2021-07-04 15:45:26.492785122 +0200 *************** *** 6,11 **** --- 6,12 ---- int has_internal_func(char_u *name); char *internal_func_name(int idx); int internal_func_check_arg_types(type_T **types, int idx, int argcount, cctx_T *cctx); + void internal_func_get_argcount(int idx, int *argcount, int *min_argcount); type_T *internal_func_ret_type(int idx, int argcount, type_T **argtypes); int internal_func_is_map(int idx); int check_internal_func(int idx, int argcount); *************** *** 21,27 **** int dynamic_feature(char_u *feature); void mzscheme_call_vim(char_u *name, typval_T *args, typval_T *rettv); void range_list_materialize(list_T *list); - float_T vim_round(float_T f); long do_searchpair(char_u *spat, char_u *mpat, char_u *epat, int dir, typval_T *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long time_limit); void f_string(typval_T *argvars, typval_T *rettv); /* vim: set ft=c : */ --- 22,27 ---- *** ../vim-8.2.3099/src/testdir/test_vim9_assign.vim 2021-06-27 15:04:00.784722722 +0200 --- src/testdir/test_vim9_assign.vim 2021-07-04 15:28:23.898868011 +0200 *************** *** 650,655 **** --- 650,664 ---- d.dd[0] = 0 END CheckDefExecFailure(lines, 'E1147:', 2) + + lines =<< trim END + def OneArg(x: bool) + enddef + def TwoArgs(x: bool, y: bool) + enddef + var fl: list = [OneArg, TwoArgs] + END + CheckDefExecAndScriptFailure(lines, 'E1012:', 5) enddef def Test_assignment_list_any_index() *** ../vim-8.2.3099/src/testdir/test_vim9_expr.vim 2021-07-03 11:58:08.373825923 +0200 --- src/testdir/test_vim9_expr.vim 2021-07-04 15:32:58.770296713 +0200 *************** *** 57,63 **** assert_equal(function('len'), Res) var RetOne: func(string): number = function('len') ! var RetTwo: func(string): number = function('winnr') var RetThat: func = g:atrue ? RetOne : RetTwo assert_equal(function('len'), RetThat) --- 57,63 ---- assert_equal(function('len'), Res) var RetOne: func(string): number = function('len') ! var RetTwo: func(string): number = function('charcol') var RetThat: func = g:atrue ? RetOne : RetTwo assert_equal(function('len'), RetThat) *** ../vim-8.2.3099/src/testdir/test_vim9_func.vim 2021-07-03 18:56:49.921634878 +0200 --- src/testdir/test_vim9_func.vim 2021-07-04 15:50:38.468164266 +0200 *************** *** 1030,1036 **** lines =<< trim END vim9script ! def g:TestFunc(f: func()) enddef legacy call g:TestFunc({-> 0}) delfunc g:TestFunc --- 1030,1036 ---- lines =<< trim END vim9script ! def g:TestFunc(f: func) enddef legacy call g:TestFunc({-> 0}) delfunc g:TestFunc *** ../vim-8.2.3099/src/version.c 2021-07-04 14:47:27.455118487 +0200 --- src/version.c 2021-07-04 15:28:47.814821050 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3100, /**/ -- From "know your smileys": :-H Is missing teeth /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///