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)
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 5704511..de7b980 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -1429,6 +1429,27 @@
'defcompile'], 'E1003:')
delfunc! g:Func
+ CheckScriptFailure([
+ 'def Func():number',
+ 'return 123',
+ 'enddef',
+ 'defcompile'], 'E1069:')
+ delfunc! g:Func
+
+ CheckScriptFailure([
+ 'def Func() :number',
+ 'return 123',
+ 'enddef',
+ 'defcompile'], 'E1059:')
+ delfunc! g:Func
+
+ CheckScriptFailure([
+ 'def Func() : number',
+ 'return 123',
+ 'enddef',
+ 'defcompile'], 'E1059:')
+ delfunc! g:Func
+
CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
delfunc! g:Func
CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
diff --git a/src/userfunc.c b/src/userfunc.c
index 79a6621..7a7617f 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -4066,8 +4066,15 @@
if (eap->cmdidx == CMD_def)
{
// find the return type: :def Func(): type
- if (*p == ':')
+ if (*skipwhite(p) == ':')
{
+ if (*p != ':')
+ {
+ semsg(_(e_no_white_space_allowed_before_colon_str), p);
+ p = skipwhite(p);
+ }
+ else if (!IS_WHITE_OR_NUL(p[1]))
+ semsg(_(e_white_space_required_after_str_str), ":", p);
ret_type = skipwhite(p + 1);
p = skip_type(ret_type, FALSE);
if (p > ret_type)
diff --git a/src/version.c b/src/version.c
index 3e209fe..aacefc0 100644
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3317,
+/**/
3316,
/**/
3315,