]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.2371: Vim9: crash when using types in :for with unpack v8.2.2371
authorBram Moolenaar <Bram@vim.org>
Sun, 17 Jan 2021 19:23:38 +0000 (20:23 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 17 Jan 2021 19:23:38 +0000 (20:23 +0100)
Problem:    Vim9: crash when using types in :for with unpack.
Solution:   Check for skip_var_list() failing. Pass include_type to
            skip_var_one(). Skip type when compiling. (closes #7694)

src/evalvars.c
src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index 155f603b5077ff66441338ed5304495c67eff818..d98d9e4708fada5576efb9418e73aedc83acf2aa 100644 (file)
@@ -1019,7 +1019,7 @@ skip_var_list(
        for (;;)
        {
            p = skipwhite(p + 1);       // skip whites after '[', ';' or ','
-           s = skip_var_one(p, FALSE);
+           s = skip_var_one(p, include_type);
            if (s == p)
            {
                if (!silent)
@@ -1067,11 +1067,14 @@ skip_var_one(char_u *arg, int include_type)
        return arg + 2;
     end = find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg,
                                   NULL, NULL, FNE_INCL_BR | FNE_CHECK_START);
+
+    // "a: type" is declaring variable "a" with a type, not "a:".
+    // Same for "s: type".
+    if (end == arg + 2 && end[-1] == ':')
+       --end;
+
     if (include_type && in_vim9script())
     {
-       // "a: type" is declaring variable "a" with a type, not "a:".
-       if (end == arg + 2 && end[-1] == ':')
-           --end;
        if (*end == ':')
            end = skip_type(skipwhite(end + 1), FALSE);
     }
index 478c394603fe87fc9d0fad1f79adbe2d5f9f6b99..957671c53b03148a4b1bb471cff31c9026f5e807 100644 (file)
@@ -2060,6 +2060,12 @@ def Test_for_loop()
     total += nr
   endfor
   assert_equal(6, total)
+
+  var res = ""
+  for [n: number, s: string] in [[1, 'a'], [2, 'b']]
+    res ..= n .. s
+  endfor
+  assert_equal('1a2b', res)
 enddef
 
 def Test_for_loop_fails()
index ecb0c4355e51b68df5709bb3673d35d1b9b523fd..289854e89ebcd6ac676b045cd8e0fa6e0dd92b4c 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2371,
 /**/
     2370,
 /**/
index fb7aeddd49abde18feb996d303ab3dec9949815b..01bf2c19a8eae6e22cc054737f5cc7851f3e8fa7 100644 (file)
@@ -6884,6 +6884,8 @@ compile_for(char_u *arg_start, cctx_T *cctx)
     int                idx;
 
     p = skip_var_list(arg_start, TRUE, &var_count, &semicolon, FALSE);
+    if (p == NULL)
+       return NULL;
     if (var_count == 0)
        var_count = 1;
 
@@ -7018,6 +7020,8 @@ compile_for(char_u *arg_start, cctx_T *cctx)
            generate_STORE(cctx, ISN_STORE, var_lvar->lv_idx, NULL);
        }
 
+       if (*p == ':')
+           p = skip_type(skipwhite(p + 1), FALSE);
        if (*p == ',' || *p == ';')
            ++p;
        arg = skipwhite(p);