To: vim_dev@googlegroups.com Subject: Patch 9.0.0726 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0726 Problem: Looping over list of lists and changing the list contents works in Vim9 script, not in a compiled function. Solution: Mark the loop variable final instead of const. (closes #11347) Files: src/vim9cmds.c, src/testdir/test_vim9_script.vim *** ../vim-9.0.0725/src/vim9cmds.c 2022-10-11 20:04:05.880795466 +0100 --- src/vim9cmds.c 2022-10-11 21:40:16.862302526 +0100 *************** *** 1048,1054 **** && need_type_where(item_type, lhs_type, -1, where, cctx, FALSE, FALSE) == FAIL) goto failed; ! var_lvar = reserve_local(cctx, arg, varlen, ASSIGN_CONST, lhs_type); if (var_lvar == NULL) // out of memory or used as an argument --- 1048,1054 ---- && need_type_where(item_type, lhs_type, -1, where, cctx, FALSE, FALSE) == FAIL) goto failed; ! var_lvar = reserve_local(cctx, arg, varlen, ASSIGN_FINAL, lhs_type); if (var_lvar == NULL) // out of memory or used as an argument *** ../vim-9.0.0725/src/testdir/test_vim9_script.vim 2022-10-11 20:04:05.880795466 +0100 --- src/testdir/test_vim9_script.vim 2022-10-11 21:40:41.122253827 +0100 *************** *** 2275,2280 **** --- 2275,2294 ---- v9.CheckDefAndScriptSuccess(lines) enddef + def Test_for_loop_list_of_lists() + # loop variable is final, not const + var lines =<< trim END + # Filter out all odd numbers in each sublist + var list: list> = [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4]] + for i in list + filter(i, (_, n: number): bool => n % 2 == 0) + endfor + + assert_equal([[], [2], [2], [2, 4]], list) + END + v9.CheckDefAndScriptSuccess(lines) + enddef + def Test_for_loop_with_closure() # using the loop variable in a closure results in the last used value var lines =<< trim END *** ../vim-9.0.0725/src/version.c 2022-10-11 21:01:44.382815392 +0100 --- src/version.c 2022-10-11 21:36:42.062756265 +0100 *************** *** 701,702 **** --- 701,704 ---- { /* Add new patch number below this line */ + /**/ + 726, /**/ -- ARTHUR: Shut up! Will you shut up! DENNIS: Ah, now we see the violence inherent in the system. ARTHUR: Shut up! DENNIS: Oh! Come and see the violence inherent in the system! HELP! HELP! I'm being repressed! The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///