Mercurial > vim
changeset 23545:987fb6e8a376 v8.2.2315
patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end
Commit: https://github.com/vim/vim/commit/832ea89ca90cdff019ee7cf31d5c44bfa164313a
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 8 21:55:26 2021 +0100
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 https://github.com/vim/vim/issues/7640)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 08 Jan 2021 22:00:04 +0100 |
parents | f1518df5eefa |
children | b3e66d8b2e93 |
files | src/testdir/test_vim9_func.vim src/userfunc.c src/version.c |
diffstat | 3 files changed, 14 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -3444,8 +3444,10 @@ define_function(exarg_T *eap, char_u *na ; // 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 *na // 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))