]> granicus.if.org Git - vim/commitdiff
patch 8.2.2315: Vim9: "enddef" as dict key misintepreted as function end v8.2.2315
authorBram Moolenaar <Bram@vim.org>
Fri, 8 Jan 2021 20:55:26 +0000 (21:55 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 8 Jan 2021 20:55:26 +0000 (21:55 +0100)
Problem:    Vim9: "enddef" as dict key misintepreted as function end.
Solution:   Check for following colon. (closes #7640)

src/testdir/test_vim9_func.vim
src/userfunc.c
src/version.c

index 9f19ebda9a309c3ba70c1ca394f6dfabac5ecdf9..fb37401a22de7697f5dc7ffbf554f1a8aea61579 100644 (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
index 814d400fb2d437555f8ba3382f096f3c32b332be..1918e541f53b12c5b9837858849d08ec11e0e45c 100644 (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))
index 7ab3b0142ccc7ca76077dbaa3179c8283ef0aa19..10786659569f452096841660a835850a4e018678 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2315,
 /**/
     2314,
 /**/