To: vim_dev@googlegroups.com Subject: Patch 8.2.3334 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3334 Problem: Vim9: not enough tests run with Vim9. Solution: Run a few more tests in Vim9 script and :def function. Fix islocked(). Fix error for locking local variable. Files: src/evalfunc.c, src/vim9compile.c, src/testdir/test_listdict.vim *** ../vim-8.2.3333/src/evalfunc.c 2021-08-08 15:51:07.119909726 +0200 --- src/evalfunc.c 2021-08-12 16:46:21.151365252 +0200 *************** *** 6556,6562 **** return; end = get_lval(tv_get_string(&argvars[0]), NULL, &lv, FALSE, FALSE, ! GLV_NO_AUTOLOAD | GLV_READ_ONLY, FNE_CHECK_START); if (end != NULL && lv.ll_name != NULL) { if (*end != NUL) --- 6556,6563 ---- return; end = get_lval(tv_get_string(&argvars[0]), NULL, &lv, FALSE, FALSE, ! GLV_NO_AUTOLOAD | GLV_READ_ONLY | GLV_NO_DECL, ! FNE_CHECK_START); if (end != NULL && lv.ll_name != NULL) { if (*end != NUL) *** ../vim-8.2.3333/src/vim9compile.c 2021-08-11 21:49:19.626869328 +0200 --- src/vim9compile.c 2021-08-12 16:58:36.317843673 +0200 *************** *** 7433,7439 **** // Cannot use :lockvar and :unlockvar on local variables. if (p[1] != ':') { ! char_u *end = skip_var_one(p, FALSE); if (lookup_local(p, end - p, NULL, cctx) == OK) { --- 7433,7439 ---- // Cannot use :lockvar and :unlockvar on local variables. if (p[1] != ':') { ! char_u *end = find_name_end(p, NULL, NULL, FNE_CHECK_START); if (lookup_local(p, end - p, NULL, cctx) == OK) { *** ../vim-8.2.3333/src/testdir/test_listdict.vim 2021-08-12 10:39:06.740748860 +0200 --- src/testdir/test_listdict.vim 2021-08-12 17:04:45.449082321 +0200 *************** *** 482,576 **** " Nasty: deepcopy() dict that refers to itself (fails when noref used) func Test_dict_deepcopy() ! let d = {1:1, 2:2} ! let l = [4, d, 6] ! let d[3] = l ! let dc = deepcopy(d) ! call assert_fails('call deepcopy(d, 1)', 'E698:') ! let l2 = [0, l, l, 3] ! let l[1] = l2 ! let l3 = deepcopy(l2) ! call assert_true(l3[1] is l3[2]) call assert_fails("call deepcopy([1, 2], 2)", 'E1023:') endfunc " Locked variables func Test_list_locked_var() ! let expected = [ ! \ [['1000-000', 'ppppppF'], ! \ ['0000-000', 'ppppppp'], ! \ ['0000-000', 'ppppppp']], ! \ [['1000-000', 'ppppppF'], ! \ ['0000-000', 'ppppppp'], ! \ ['0000-000', 'ppppppp']], ! \ [['1100-100', 'ppFppFF'], ! \ ['0000-000', 'ppppppp'], ! \ ['0000-000', 'ppppppp']], ! \ [['1110-110', 'pFFpFFF'], ! \ ['0010-010', 'pFppFpp'], ! \ ['0000-000', 'ppppppp']], ! \ [['1111-111', 'FFFFFFF'], ! \ ['0011-011', 'FFpFFpp'], ! \ ['0000-000', 'ppppppp']] ! \ ] ! for depth in range(5) ! for u in range(3) ! unlet! l ! let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] ! exe "lockvar " . depth . " l" ! if u == 1 ! exe "unlockvar l" ! elseif u == 2 ! exe "unlockvar " . depth . " l" ! endif ! let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]") ! call assert_equal(expected[depth][u][0], ps, 'depth: ' .. depth) ! let ps = '' ! try ! let l[1][1][0] = 99 ! let ps .= 'p' ! catch ! let ps .= 'F' ! endtry ! try ! let l[1][1] = [99] ! let ps .= 'p' ! catch ! let ps .= 'F' ! endtry ! try ! let l[1] = [99] ! let ps .= 'p' ! catch ! let ps .= 'F' ! endtry ! try ! let l[2]['6'][7] = 99 ! let ps .= 'p' ! catch ! let ps .= 'F' ! endtry ! try ! let l[2][6] = {99: 99} ! let ps .= 'p' ! catch ! let ps .= 'F' ! endtry ! try ! let l[2] = {99: 99} ! let ps .= 'p' ! catch ! let ps .= 'F' ! endtry ! try ! let l = [99] ! let ps .= 'p' ! catch ! let ps .= 'F' ! endtry ! call assert_equal(expected[depth][u][1], ps, 'depth: ' .. depth) ! endfor ! endfor call assert_fails("let x=islocked('a b')", 'E488:') let mylist = [1, 2, 3] call assert_fails("let x = islocked('mylist[1:2]')", 'E786:') --- 482,593 ---- " Nasty: deepcopy() dict that refers to itself (fails when noref used) func Test_dict_deepcopy() ! let lines =<< trim END ! VAR d = {1: 1, 2: '2'} ! VAR l = [4, d, 6] ! LET d[3] = l ! VAR dc = deepcopy(d) ! call deepcopy(d, 1) ! END ! call CheckLegacyAndVim9Failure(lines, 'E698:') ! ! let lines =<< trim END ! VAR d = {1: 1, 2: '2'} ! VAR l = [4, d, 6] ! LET d[3] = l ! VAR l2 = [0, l, l, 3] ! LET l[1] = l2 ! VAR l3 = deepcopy(l2) ! call assert_true(l3[1] is l3[2]) ! END ! call CheckLegacyAndVim9Success(lines) ! call assert_fails("call deepcopy([1, 2], 2)", 'E1023:') endfunc " Locked variables func Test_list_locked_var() ! " Not tested with :def function, local vars cannot be locked. ! let lines =<< trim END ! VAR expected = [ ! \ [['1000-000', 'ppppppF'], ! \ ['0000-000', 'ppppppp'], ! \ ['0000-000', 'ppppppp']], ! \ [['1000-000', 'ppppppF'], ! \ ['0000-000', 'ppppppp'], ! \ ['0000-000', 'ppppppp']], ! \ [['1100-100', 'ppFppFF'], ! \ ['0000-000', 'ppppppp'], ! \ ['0000-000', 'ppppppp']], ! \ [['1110-110', 'pFFpFFF'], ! \ ['0010-010', 'pFppFpp'], ! \ ['0000-000', 'ppppppp']], ! \ [['1111-111', 'FFFFFFF'], ! \ ['0011-011', 'FFpFFpp'], ! \ ['0000-000', 'ppppppp']] ! \ ] ! for depth in range(5) ! for u in range(3) ! VAR l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] ! exe "lockvar " .. depth .. " l" ! if u == 1 ! exe "unlockvar l" ! elseif u == 2 ! exe "unlockvar " .. depth .. " l" ! endif ! VAR ps = islocked("l") .. islocked("l[1]") .. islocked("l[1][1]") .. islocked("l[1][1][0]") .. '-' .. islocked("l[2]") .. islocked("l[2]['6']") .. islocked("l[2]['6'][7]") ! call assert_equal(expected[depth][u][0], ps, 'depth: ' .. depth) ! LET ps = '' ! try ! LET l[1][1][0] = 99 ! LET ps ..= 'p' ! catch ! LET ps ..= 'F' ! endtry ! try ! LET l[1][1] = [99] ! LET ps ..= 'p' ! catch ! LET ps ..= 'F' ! endtry ! try ! LET l[1] = [99] ! LET ps ..= 'p' ! catch ! LET ps ..= 'F' ! endtry ! try ! LET l[2]['6'][7] = 99 ! LET ps ..= 'p' ! catch ! LET ps ..= 'F' ! endtry ! try ! LET l[2][6] = {99: 99} ! LET ps ..= 'p' ! catch ! LET ps ..= 'F' ! endtry ! try ! LET l[2] = {99: 99} ! LET ps ..= 'p' ! catch ! LET ps ..= 'F' ! endtry ! try ! LET l = [99] ! LET ps ..= 'p' ! catch ! LET ps ..= 'F' ! endtry ! call assert_equal(expected[depth][u][1], ps, 'depth: ' .. depth) ! unlock! l ! endfor ! endfor ! END ! call CheckTransLegacySuccess(lines) ! call CheckTransVim9Success(lines) ! call assert_fails("let x=islocked('a b')", 'E488:') let mylist = [1, 2, 3] call assert_fails("let x = islocked('mylist[1:2]')", 'E786:') *************** *** 580,585 **** --- 597,603 ---- " Unletting locked variables func Test_list_locked_var_unlet() + " Not tested with Vim9: script and local variables cannot be unlocked let expected = [ \ [['1000-000', 'ppppppp'], \ ['0000-000', 'ppppppp'], *************** *** 674,699 **** " unlet after lock on dict item func Test_dict_item_lock_unlet() ! let d = {'a': 99, 'b': 100} ! lockvar d.a ! unlet d.a ! call assert_equal({'b' : 100}, d) endfunc " filter() after lock on dict item func Test_dict_lock_filter() ! let d = {'a': 99, 'b': 100} ! lockvar d.a ! call filter(d, 'v:key != "a"') ! call assert_equal({'b' : 100}, d) endfunc " map() after lock on dict func Test_dict_lock_map() ! let d = {'a': 99, 'b': 100} ! lockvar 1 d ! call map(d, 'v:val + 200') ! call assert_equal({'a' : 299, 'b' : 300}, d) endfunc " No extend() after lock on dict item --- 692,734 ---- " unlet after lock on dict item func Test_dict_item_lock_unlet() ! let lines =<< trim END ! VAR d = {'a': 99, 'b': 100} ! lockvar d.a ! unlet d.a ! call assert_equal({'b': 100}, d) ! END ! " TODO: make this work in a :def function ! "call CheckLegacyAndVim9Success(lines) ! call CheckTransLegacySuccess(lines) ! call CheckTransVim9Success(lines) endfunc " filter() after lock on dict item func Test_dict_lock_filter() ! let lines =<< trim END ! VAR d = {'a': 99, 'b': 100} ! lockvar d.a ! call filter(d, 'v:key != "a"') ! call assert_equal({'b': 100}, d) ! END ! " TODO: make this work in a :def function ! "call CheckLegacyAndVim9Success(lines) ! call CheckTransLegacySuccess(lines) ! call CheckTransVim9Success(lines) endfunc " map() after lock on dict func Test_dict_lock_map() ! let lines =<< trim END ! VAR d = {'a': 99, 'b': 100} ! lockvar 1 d ! call map(d, 'v:val + 200') ! call assert_equal({'a': 299, 'b': 300}, d) ! END ! " This won't work in a :def function ! call CheckTransLegacySuccess(lines) ! call CheckTransVim9Success(lines) endfunc " No extend() after lock on dict item *** ../vim-8.2.3333/src/version.c 2021-08-12 10:39:06.740748860 +0200 --- src/version.c 2021-08-12 16:47:03.175277923 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3334, /**/ -- Time flies like an arrow. Fruit flies like a banana. /// 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 ///