To: vim_dev@googlegroups.com Subject: Patch 8.2.2371 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2371 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) Files: src/vim9compile.c, src/evalvars.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.2370/src/vim9compile.c 2021-01-16 16:06:58.122713790 +0100 --- src/vim9compile.c 2021-01-17 20:23:13.475087363 +0100 *************** *** 6884,6889 **** --- 6884,6891 ---- 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,7023 **** --- 7020,7027 ---- 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); *** ../vim-8.2.2370/src/evalvars.c 2021-01-13 19:48:41.628312470 +0100 --- src/evalvars.c 2021-01-17 20:19:14.243699620 +0100 *************** *** 1019,1025 **** for (;;) { p = skipwhite(p + 1); // skip whites after '[', ';' or ',' ! s = skip_var_one(p, FALSE); if (s == p) { if (!silent) --- 1019,1025 ---- for (;;) { p = skipwhite(p + 1); // skip whites after '[', ';' or ',' ! s = skip_var_one(p, include_type); if (s == p) { if (!silent) *************** *** 1067,1077 **** return arg + 2; end = find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); 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); } --- 1067,1080 ---- 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()) { if (*end == ':') end = skip_type(skipwhite(end + 1), FALSE); } *** ../vim-8.2.2370/src/testdir/test_vim9_script.vim 2021-01-17 19:20:28.136651661 +0100 --- src/testdir/test_vim9_script.vim 2021-01-17 20:21:40.699323884 +0100 *************** *** 2060,2065 **** --- 2060,2071 ---- 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() *** ../vim-8.2.2370/src/version.c 2021-01-17 19:20:28.136651661 +0100 --- src/version.c 2021-01-17 20:04:51.358048017 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2371, /**/ -- hundred-and-one symptoms of being an internet addict: 172. You join listservers just for the extra e-mail. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///