Skip to content

Commit 33ea9fd

Browse files
committed
patch 8.2.3317: Vim9: No error for missing white space before return type
Problem: Vim9: No error for missing white space before return type. Solution: Check for white space. (closes #8733)
1 parent 80a070c commit 33ea9fd

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/testdir/test_vim9_func.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,27 @@ def Test_return_type_wrong()
14291429
'defcompile'], 'E1003:')
14301430
delfunc! g:Func
14311431

1432+
CheckScriptFailure([
1433+
'def Func():number',
1434+
'return 123',
1435+
'enddef',
1436+
'defcompile'], 'E1069:')
1437+
delfunc! g:Func
1438+
1439+
CheckScriptFailure([
1440+
'def Func() :number',
1441+
'return 123',
1442+
'enddef',
1443+
'defcompile'], 'E1059:')
1444+
delfunc! g:Func
1445+
1446+
CheckScriptFailure([
1447+
'def Func() : number',
1448+
'return 123',
1449+
'enddef',
1450+
'defcompile'], 'E1059:')
1451+
delfunc! g:Func
1452+
14321453
CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
14331454
delfunc! g:Func
14341455
CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')

src/userfunc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4066,8 +4066,15 @@ define_function(exarg_T *eap, char_u *name_arg)
40664066
if (eap->cmdidx == CMD_def)
40674067
{
40684068
// find the return type: :def Func(): type
4069-
if (*p == ':')
4069+
if (*skipwhite(p) == ':')
40704070
{
4071+
if (*p != ':')
4072+
{
4073+
semsg(_(e_no_white_space_allowed_before_colon_str), p);
4074+
p = skipwhite(p);
4075+
}
4076+
else if (!IS_WHITE_OR_NUL(p[1]))
4077+
semsg(_(e_white_space_required_after_str_str), ":", p);
40714078
ret_type = skipwhite(p + 1);
40724079
p = skip_type(ret_type, FALSE);
40734080
if (p > ret_type)

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+
3317,
758760
/**/
759761
3316,
760762
/**/

0 commit comments

Comments
 (0)