0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

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)
This commit is contained in:
Bram Moolenaar
2021-01-08 21:55:26 +01:00
parent 299f3036ec
commit 832ea89ca9
3 changed files with 14 additions and 2 deletions

View File

@@ -116,6 +116,14 @@ def Test_missing_endfunc_enddef()
CheckScriptFailure(lines, 'E126:', 2)
enddef
def Test_enddef_dict_key()
var d = {
enddef: 'x',
endfunc: 'y',
}
assert_equal({enddef: 'x', endfunc: 'y'}, d)
enddef
def ReturnString(): string
return 'string'
enddef

View File

@@ -3444,8 +3444,10 @@ define_function(exarg_T *eap, char_u *name_arg)
;
// Check for "endfunction" or "enddef".
// When a ":" follows it must be a dict key; "enddef: value,"
if (checkforcmd(&p, nesting_def[nesting]
? "enddef" : "endfunction", 4))
? "enddef" : "endfunction", 4)
&& *p != ':')
{
if (nesting-- == 0)
{
@@ -3484,7 +3486,7 @@ define_function(exarg_T *eap, char_u *name_arg)
// not find it.
else if (nesting_def[nesting])
{
if (checkforcmd(&p, "endfunction", 4))
if (checkforcmd(&p, "endfunction", 4) && *p != ':')
emsg(_(e_mismatched_endfunction));
}
else if (eap->cmdidx == CMD_def && checkforcmd(&p, "enddef", 4))

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2315,
/**/
2314,
/**/