Skip to content

Commit 832ea89

Browse files
committed
patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end
Problem: Vim9: "enddef" as dict key misintepreted as function end. Solution: Check for following colon. (closes #7640)
1 parent 299f303 commit 832ea89

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/testdir/test_vim9_func.vim

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

119+
def Test_enddef_dict_key()
120+
var d = {
121+
enddef: 'x',
122+
endfunc: 'y',
123+
}
124+
assert_equal({enddef: 'x', endfunc: 'y'}, d)
125+
enddef
126+
119127
def ReturnString(): string
120128
return 'string'
121129
enddef

src/userfunc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,8 +3444,10 @@ define_function(exarg_T *eap, char_u *name_arg)
34443444
;
34453445

34463446
// Check for "endfunction" or "enddef".
3447+
// When a ":" follows it must be a dict key; "enddef: value,"
34473448
if (checkforcmd(&p, nesting_def[nesting]
3448-
? "enddef" : "endfunction", 4))
3449+
? "enddef" : "endfunction", 4)
3450+
&& *p != ':')
34493451
{
34503452
if (nesting-- == 0)
34513453
{
@@ -3484,7 +3486,7 @@ define_function(exarg_T *eap, char_u *name_arg)
34843486
// not find it.
34853487
else if (nesting_def[nesting])
34863488
{
3487-
if (checkforcmd(&p, "endfunction", 4))
3489+
if (checkforcmd(&p, "endfunction", 4) && *p != ':')
34883490
emsg(_(e_mismatched_endfunction));
34893491
}
34903492
else if (eap->cmdidx == CMD_def && checkforcmd(&p, "enddef", 4))

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+
2315,
753755
/**/
754756
2314,
755757
/**/

0 commit comments

Comments
 (0)