From: Bram Moolenaar Date: Fri, 8 Jan 2021 20:55:26 +0000 (+0100) Subject: patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end X-Git-Tag: v8.2.2315 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=832ea89ca90cdff019ee7cf31d5c44bfa164313a;p=vim 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) --- diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim index 9f19ebda9..fb37401a2 100644 --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -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 diff --git a/src/userfunc.c b/src/userfunc.c index 814d400fb..1918e541f 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -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)) diff --git a/src/version.c b/src/version.c index 7ab3b0142..107866595 100644 --- a/src/version.c +++ b/src/version.c @@ -750,6 +750,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2315, /**/ 2314, /**/