]> granicus.if.org Git - vim/commitdiff
patch 8.2.1302: Vim9: varargs arg after optional arg does not work v8.2.1302
authorBram Moolenaar <Bram@vim.org>
Sun, 26 Jul 2020 16:33:09 +0000 (18:33 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 26 Jul 2020 16:33:09 +0000 (18:33 +0200)
Problem:    Vim9: varargs arg after optional arg does not work
Solution:   Check for the "..." first. (issue #6507)

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

index 0d39d5764984082b01284f8053fd6ba3b3beb2b7..c05e98e70451a581303064c1dac107aef3feb9ca 100644 (file)
@@ -376,6 +376,28 @@ def Test_call_funcref()
     assert_equal([1, 2, 3], g:echo)
   END
   CheckScriptSuccess(lines)
+
+  lines =<< trim END
+    vim9script
+    def OptAndVar(nr: number, opt = 12, ...l: list<number>): number
+      g:optarg = opt
+      g:listarg = l
+      return nr
+    enddef
+    let Funcref: func(number, ?number, ...list<number>): number = function('OptAndVar')
+    assert_equal(10, Funcref(10))
+    assert_equal(12, g:optarg)
+    assert_equal([], g:listarg)
+
+    assert_equal(11, Funcref(11, 22))
+    assert_equal(22, g:optarg)
+    assert_equal([], g:listarg)
+
+    assert_equal(17, Funcref(17, 18, 1, 2, 3))
+    assert_equal(18, g:optarg)
+    assert_equal([1, 2, 3], g:listarg)
+  END
+  CheckScriptSuccess(lines)
 enddef
 
 let SomeFunc = function('len')
index 2481434407c52bc78b93e693b3ec2b3dc473445d..e969ab0f3529f8451d36aa5822f4bbab323f11d9 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1302,
 /**/
     1301,
 /**/
index 31e761284e26ecf51e1aab003d7bc906dcf1d12c..8efb1f672fd8e27143d9bc1b48353d0b29a430e3 100644 (file)
@@ -2106,16 +2106,16 @@ parse_type(char_u **arg, garray_T *type_gap)
                                first_optional = argcount;
                            ++p;
                        }
-                       else if (first_optional != -1)
-                       {
-                           emsg(_("E1007: mandatory argument after optional argument"));
-                           return &t_any;
-                       }
                        else if (STRNCMP(p, "...", 3) == 0)
                        {
                            flags |= TTFLAG_VARARGS;
                            p += 3;
                        }
+                       else if (first_optional != -1)
+                       {
+                           emsg(_("E1007: mandatory argument after optional argument"));
+                           return &t_any;
+                       }
 
                        arg_type[argcount++] = parse_type(&p, type_gap);