To: vim_dev@googlegroups.com Subject: Patch 8.2.3249 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3249 Problem: Vim9: error for re-imported function with default argument. Solution: Do not check argument type if it is still unknown. (closes #8653) Files: src/vim9type.c, src/proto/vim9type.pro, src/vim9script.c, src/vim.h, src/eval.c, src/vim9execute.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.3248/src/vim9type.c 2021-07-22 14:58:43.473967313 +0200 --- src/vim9type.c 2021-07-29 22:39:16.524448095 +0200 *************** *** 954,962 **** /* * Check if "type1" and "type2" are exactly the same. */ int ! equal_type(type_T *type1, type_T *type2) { int i; --- 954,964 ---- /* * Check if "type1" and "type2" are exactly the same. + * "flags" can have ETYPE_ARG_UNKNOWN, which means that an unknown argument + * type in "type1" is accepted. */ int ! equal_type(type_T *type1, type_T *type2, int flags) { int i; *************** *** 981,997 **** break; // not composite is always OK case VAR_LIST: case VAR_DICT: ! 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; } --- 983,1001 ---- break; // not composite is always OK case VAR_LIST: case VAR_DICT: ! return equal_type(type1->tt_member, type2->tt_member, flags); case VAR_FUNC: case VAR_PARTIAL: ! if (!equal_type(type1->tt_member, type2->tt_member, flags) || 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 ((flags & ETYPE_ARG_UNKNOWN) == 0 ! && !equal_type(type1->tt_args[i], type2->tt_args[i], ! flags)) return FALSE; return TRUE; } *************** *** 1005,1011 **** void common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap) { ! if (equal_type(type1, type2)) { *dest = type1; return; --- 1009,1015 ---- void common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap) { ! if (equal_type(type1, type2, 0)) { *dest = type1; return; *** ../vim-8.2.3248/src/proto/vim9type.pro 2021-07-22 14:58:43.473967313 +0200 --- src/proto/vim9type.pro 2021-07-29 22:37:18.052707704 +0200 *************** *** 20,26 **** int check_argument_types(type_T *type, typval_T *argvars, int argcount, char_u *name); char_u *skip_type(char_u *start, int optional); type_T *parse_type(char_u **arg, garray_T *type_gap, int give_error); ! int equal_type(type_T *type1, type_T *type2); void common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap); type_T *get_member_type_from_stack(type_T **stack_top, int count, int skip, garray_T *type_gap); char *vartype_name(vartype_T type); --- 20,26 ---- int check_argument_types(type_T *type, typval_T *argvars, int argcount, char_u *name); char_u *skip_type(char_u *start, int optional); type_T *parse_type(char_u **arg, garray_T *type_gap, int give_error); ! int equal_type(type_T *type1, type_T *type2, int flags); void common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap); type_T *get_member_type_from_stack(type_T **stack_top, int count, int skip, garray_T *type_gap); char *vartype_name(vartype_T type); *** ../vim-8.2.3248/src/vim9script.c 2021-07-29 22:25:01.894202718 +0200 --- src/vim9script.c 2021-07-29 22:42:50.363945997 +0200 *************** *** 623,631 **** && (imported->imp_flags & IMP_FLAGS_RELOAD) && imported->imp_sid == sid && (idx >= 0 ! ? (equal_type(imported->imp_type, type) && imported->imp_var_vals_idx == idx) ! : (equal_type(imported->imp_type, ufunc->uf_func_type) && STRCMP(imported->imp_funcname, ufunc->uf_name) == 0))) { --- 623,632 ---- && (imported->imp_flags & IMP_FLAGS_RELOAD) && imported->imp_sid == sid && (idx >= 0 ! ? (equal_type(imported->imp_type, type, 0) && imported->imp_var_vals_idx == idx) ! : (equal_type(imported->imp_type, ufunc->uf_func_type, ! ETYPE_ARG_UNKNOWN) && STRCMP(imported->imp_funcname, ufunc->uf_name) == 0))) { *** ../vim-8.2.3248/src/vim.h 2021-07-29 20:37:45.656199169 +0200 --- src/vim.h 2021-07-29 22:37:46.616648365 +0200 *************** *** 2736,2739 **** --- 2736,2742 ---- // Maximum number of characters that can be fuzzy matched #define MAX_FUZZY_MATCHES 256 + // flags for equal_type() + #define ETYPE_ARG_UNKNOWN 1 + #endif // VIM__H *** ../vim-8.2.3248/src/eval.c 2021-07-27 22:00:39.741712405 +0200 --- src/eval.c 2021-07-29 22:35:32.660926036 +0200 *************** *** 3359,3365 **** { type_T *actual = typval2type(rettv, get_copyID(), &type_list, TRUE); ! if (!equal_type(want_type, actual)) { if (want_type == &t_bool && actual != &t_bool && (actual->tt_flags & TTFLAG_BOOL_OK)) --- 3359,3365 ---- { type_T *actual = typval2type(rettv, get_copyID(), &type_list, TRUE); ! if (!equal_type(want_type, actual, 0)) { if (want_type == &t_bool && actual != &t_bool && (actual->tt_flags & TTFLAG_BOOL_OK)) *** ../vim-8.2.3248/src/vim9execute.c 2021-07-24 19:32:07.800733149 +0200 --- src/vim9execute.c 2021-07-29 22:35:57.860873906 +0200 *************** *** 1271,1277 **** return NULL; } sv = ((svar_T *)si->sn_var_vals.ga_data) + sref->sref_idx; ! if (!equal_type(sv->sv_type, sref->sref_type)) { emsg(_(e_script_variable_type_changed)); return NULL; --- 1271,1277 ---- return NULL; } sv = ((svar_T *)si->sn_var_vals.ga_data) + sref->sref_idx; ! if (!equal_type(sv->sv_type, sref->sref_type, 0)) { emsg(_(e_script_variable_type_changed)); return NULL; *** ../vim-8.2.3248/src/testdir/test_vim9_script.vim 2021-07-29 22:25:01.894202718 +0200 --- src/testdir/test_vim9_script.vim 2021-07-29 22:42:35.383980641 +0200 *************** *** 1626,1631 **** --- 1626,1634 ---- var lines =<< trim END vim9script export var exported = 'thexport' + + export def TheFunc(x = 0) + enddef END writefile(lines, 'XExportReload') lines =<< trim END *************** *** 1638,1643 **** --- 1641,1649 ---- return 'again' enddef + import TheFunc from './XExportReload' + TheFunc() + if exists('s:loaded') | finish | endif var s:loaded = true *** ../vim-8.2.3248/src/version.c 2021-07-29 22:25:01.898202709 +0200 --- src/version.c 2021-07-29 22:34:32.421050401 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3249, /**/ -- This is an airconditioned room, do not open Windows. /// 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 ///