Skip to content

Commit 648ea76

Browse files
committed
patch 8.2.2357: Vim9: crash when parsing function return type fails
Problem: Vim9: crash when parsing function return type fails. Solution: Bail out and set return type to "unknown". (closes #7685)
1 parent 883cf97 commit 648ea76

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/testdir/test_vim9_func.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,17 @@ def Test_return_nothing()
197197
s:nothing->assert_equal(1)
198198
enddef
199199

200+
def Test_return_invalid()
201+
var lines =<< trim END
202+
vim9script
203+
def Func(): invalid
204+
return xxx
205+
enddef
206+
defcompile
207+
END
208+
CheckScriptFailure(lines, 'E1010:', 2)
209+
enddef
210+
200211
func Increment()
201212
let g:counter += 1
202213
endfunc

src/userfunc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3886,6 +3886,12 @@ define_function(exarg_T *eap, char_u *name_arg)
38863886
{
38873887
p = ret_type;
38883888
fp->uf_ret_type = parse_type(&p, &fp->uf_type_list, TRUE);
3889+
if (fp->uf_ret_type == NULL)
3890+
{
3891+
fp->uf_ret_type = &t_void;
3892+
SOURCING_LNUM = lnum_save;
3893+
goto erret;
3894+
}
38893895
}
38903896
SOURCING_LNUM = lnum_save;
38913897
}

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2357,
753755
/**/
754756
2356,
755757
/**/

0 commit comments

Comments
 (0)