Skip to content

Commit 831bdf8

Browse files
committed
patch 8.2.3035: Vim9: crash when calling :def function with partial
Problem: Vim9: crash when calling :def function with partial and return type is not set. Solution: When the return type is not set handle like the return type is unknown. (closes #8422)
1 parent ef7be83 commit 831bdf8

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/testdir/test_vim9_func.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,20 @@ def Test_pass_legacy_lambda_to_def_func()
10051005
Foo()
10061006
END
10071007
CheckScriptSuccess(lines)
1008+
1009+
lines =<< trim END
1010+
vim9script
1011+
def g:TestFunc(f: func())
1012+
enddef
1013+
legacy call g:TestFunc({-> 0})
1014+
delfunc g:TestFunc
1015+
1016+
def g:TestFunc(f: func(number))
1017+
enddef
1018+
legacy call g:TestFunc({nr -> 0})
1019+
delfunc g:TestFunc
1020+
END
1021+
CheckScriptSuccess(lines)
10081022
enddef
10091023

10101024
" Default arg and varargs

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+
3035,
758760
/**/
759761
3034,
760762
/**/

src/vim9type.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ alloc_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
171171
if (type == NULL)
172172
return &t_any;
173173
type->tt_type = VAR_FUNC;
174-
type->tt_member = ret_type;
174+
type->tt_member = ret_type == NULL ? &t_unknown : ret_type;
175175
type->tt_argcount = argcount;
176176
type->tt_args = NULL;
177177
return type;
@@ -188,7 +188,7 @@ get_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
188188
// recognize commonly used types
189189
if (argcount <= 0)
190190
{
191-
if (ret_type == &t_unknown)
191+
if (ret_type == &t_unknown || ret_type == NULL)
192192
{
193193
// (argcount == 0) is not possible
194194
return &t_func_unknown;

0 commit comments

Comments
 (0)