Skip to content

Commit 4efd994

Browse files
committed
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Problem: Vim9: no need to allow white space before "(" for :def. Solution: Give an error for stray white space. (issue #7734)
1 parent 107e9ce commit 4efd994

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/testdir/test_vim9_func.vim

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,38 @@ def Test_missing_endfunc_enddef()
116116
CheckScriptFailure(lines, 'E126:', 2)
117117
enddef
118118

119+
def Test_white_space_before_paren()
120+
var lines =<< trim END
121+
vim9script
122+
def Test ()
123+
echo 'test'
124+
enddef
125+
END
126+
CheckScriptFailure(lines, 'E1068:', 2)
127+
128+
lines =<< trim END
129+
vim9script
130+
func Test ()
131+
echo 'test'
132+
endfunc
133+
END
134+
CheckScriptFailure(lines, 'E1068:', 2)
135+
136+
lines =<< trim END
137+
def Test ()
138+
echo 'test'
139+
enddef
140+
END
141+
CheckScriptFailure(lines, 'E1068:', 1)
142+
143+
lines =<< trim END
144+
func Test ()
145+
echo 'test'
146+
endfunc
147+
END
148+
CheckScriptSuccess(lines)
149+
enddef
150+
119151
def Test_enddef_dict_key()
120152
var d = {
121153
enddef: 'x',

src/userfunc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,6 +3199,12 @@ define_function(exarg_T *eap, char_u *name_arg)
31993199
p = vim_strchr(p, '(');
32003200
}
32013201

3202+
if ((vim9script || eap->cmdidx == CMD_def) && VIM_ISWHITE(p[-1]))
3203+
{
3204+
semsg(_(e_no_white_space_allowed_before_str), "(");
3205+
goto ret_free;
3206+
}
3207+
32023208
// In Vim9 script only global functions can be redefined.
32033209
if (vim9script && eap->forceit && !is_global)
32043210
{

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+
2405,
753755
/**/
754756
2404,
755757
/**/

0 commit comments

Comments
 (0)