Skip to content

Commit 60dc827

Browse files
committed
patch 8.2.3249: Vim9: error for re-imported function with default argument
Problem: Vim9: error for re-imported function with default argument. Solution: Do not check argument type if it is still unknown. (closes #8653)
1 parent 921ba52 commit 60dc827

File tree

8 files changed

+26
-10
lines changed

8 files changed

+26
-10
lines changed

src/eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3359,7 +3359,7 @@ eval7t(
33593359
{
33603360
type_T *actual = typval2type(rettv, get_copyID(), &type_list, TRUE);
33613361

3362-
if (!equal_type(want_type, actual))
3362+
if (!equal_type(want_type, actual, 0))
33633363
{
33643364
if (want_type == &t_bool && actual != &t_bool
33653365
&& (actual->tt_flags & TTFLAG_BOOL_OK))

src/proto/vim9type.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int check_type(type_T *expected, type_T *actual, int give_msg, where_T where);
2020
int check_argument_types(type_T *type, typval_T *argvars, int argcount, char_u *name);
2121
char_u *skip_type(char_u *start, int optional);
2222
type_T *parse_type(char_u **arg, garray_T *type_gap, int give_error);
23-
int equal_type(type_T *type1, type_T *type2);
23+
int equal_type(type_T *type1, type_T *type2, int flags);
2424
void common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap);
2525
type_T *get_member_type_from_stack(type_T **stack_top, int count, int skip, garray_T *type_gap);
2626
char *vartype_name(vartype_T type);

src/testdir/test_vim9_script.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,9 @@ def Test_vim9script_reload_noclear()
16261626
var lines =<< trim END
16271627
vim9script
16281628
export var exported = 'thexport'
1629+
1630+
export def TheFunc(x = 0)
1631+
enddef
16291632
END
16301633
writefile(lines, 'XExportReload')
16311634
lines =<< trim END
@@ -1638,6 +1641,9 @@ def Test_vim9script_reload_noclear()
16381641
return 'again'
16391642
enddef
16401643

1644+
import TheFunc from './XExportReload'
1645+
TheFunc()
1646+
16411647
if exists('s:loaded') | finish | endif
16421648
var s:loaded = true
16431649

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3249,
758760
/**/
759761
3248,
760762
/**/

src/vim.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,4 +2736,7 @@ long elapsed(DWORD start_tick);
27362736
// Maximum number of characters that can be fuzzy matched
27372737
#define MAX_FUZZY_MATCHES 256
27382738

2739+
// flags for equal_type()
2740+
#define ETYPE_ARG_UNKNOWN 1
2741+
27392742
#endif // VIM__H

src/vim9execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ get_script_svar(scriptref_T *sref, ectx_T *ectx)
12711271
return NULL;
12721272
}
12731273
sv = ((svar_T *)si->sn_var_vals.ga_data) + sref->sref_idx;
1274-
if (!equal_type(sv->sv_type, sref->sref_type))
1274+
if (!equal_type(sv->sv_type, sref->sref_type, 0))
12751275
{
12761276
emsg(_(e_script_variable_type_changed));
12771277
return NULL;

src/vim9script.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,10 @@ handle_import(
623623
&& (imported->imp_flags & IMP_FLAGS_RELOAD)
624624
&& imported->imp_sid == sid
625625
&& (idx >= 0
626-
? (equal_type(imported->imp_type, type)
626+
? (equal_type(imported->imp_type, type, 0)
627627
&& imported->imp_var_vals_idx == idx)
628-
: (equal_type(imported->imp_type, ufunc->uf_func_type)
628+
: (equal_type(imported->imp_type, ufunc->uf_func_type,
629+
ETYPE_ARG_UNKNOWN)
629630
&& STRCMP(imported->imp_funcname,
630631
ufunc->uf_name) == 0)))
631632
{

src/vim9type.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -954,9 +954,11 @@ parse_type(char_u **arg, garray_T *type_gap, int give_error)
954954

955955
/*
956956
* Check if "type1" and "type2" are exactly the same.
957+
* "flags" can have ETYPE_ARG_UNKNOWN, which means that an unknown argument
958+
* type in "type1" is accepted.
957959
*/
958960
int
959-
equal_type(type_T *type1, type_T *type2)
961+
equal_type(type_T *type1, type_T *type2, int flags)
960962
{
961963
int i;
962964

@@ -981,17 +983,19 @@ equal_type(type_T *type1, type_T *type2)
981983
break; // not composite is always OK
982984
case VAR_LIST:
983985
case VAR_DICT:
984-
return equal_type(type1->tt_member, type2->tt_member);
986+
return equal_type(type1->tt_member, type2->tt_member, flags);
985987
case VAR_FUNC:
986988
case VAR_PARTIAL:
987-
if (!equal_type(type1->tt_member, type2->tt_member)
989+
if (!equal_type(type1->tt_member, type2->tt_member, flags)
988990
|| type1->tt_argcount != type2->tt_argcount)
989991
return FALSE;
990992
if (type1->tt_argcount < 0
991993
|| type1->tt_args == NULL || type2->tt_args == NULL)
992994
return TRUE;
993995
for (i = 0; i < type1->tt_argcount; ++i)
994-
if (!equal_type(type1->tt_args[i], type2->tt_args[i]))
996+
if ((flags & ETYPE_ARG_UNKNOWN) == 0
997+
&& !equal_type(type1->tt_args[i], type2->tt_args[i],
998+
flags))
995999
return FALSE;
9961000
return TRUE;
9971001
}
@@ -1005,7 +1009,7 @@ equal_type(type_T *type1, type_T *type2)
10051009
void
10061010
common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap)
10071011
{
1008-
if (equal_type(type1, type2))
1012+
if (equal_type(type1, type2, 0))
10091013
{
10101014
*dest = type1;
10111015
return;

0 commit comments

Comments
 (0)