Skip to content

Commit bd77aa9

Browse files
committed
patch 8.2.3334: Vim9: not enough tests run with Vim9
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.
1 parent 3e9c0b9 commit bd77aa9

File tree

4 files changed

+136
-98
lines changed

4 files changed

+136
-98
lines changed

src/evalfunc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6556,7 +6556,8 @@ f_islocked(typval_T *argvars, typval_T *rettv)
65566556
return;
65576557

65586558
end = get_lval(tv_get_string(&argvars[0]), NULL, &lv, FALSE, FALSE,
6559-
GLV_NO_AUTOLOAD | GLV_READ_ONLY, FNE_CHECK_START);
6559+
GLV_NO_AUTOLOAD | GLV_READ_ONLY | GLV_NO_DECL,
6560+
FNE_CHECK_START);
65606561
if (end != NULL && lv.ll_name != NULL)
65616562
{
65626563
if (*end != NUL)

src/testdir/test_listdict.vim

Lines changed: 131 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -482,95 +482,112 @@ endfunc
482482

483483
" Nasty: deepcopy() dict that refers to itself (fails when noref used)
484484
func Test_dict_deepcopy()
485-
let d = {1:1, 2:2}
486-
let l = [4, d, 6]
487-
let d[3] = l
488-
let dc = deepcopy(d)
489-
call assert_fails('call deepcopy(d, 1)', 'E698:')
490-
let l2 = [0, l, l, 3]
491-
let l[1] = l2
492-
let l3 = deepcopy(l2)
493-
call assert_true(l3[1] is l3[2])
485+
let lines =<< trim END
486+
VAR d = {1: 1, 2: '2'}
487+
VAR l = [4, d, 6]
488+
LET d[3] = l
489+
VAR dc = deepcopy(d)
490+
call deepcopy(d, 1)
491+
END
492+
call CheckLegacyAndVim9Failure(lines, 'E698:')
493+
494+
let lines =<< trim END
495+
VAR d = {1: 1, 2: '2'}
496+
VAR l = [4, d, 6]
497+
LET d[3] = l
498+
VAR l2 = [0, l, l, 3]
499+
LET l[1] = l2
500+
VAR l3 = deepcopy(l2)
501+
call assert_true(l3[1] is l3[2])
502+
END
503+
call CheckLegacyAndVim9Success(lines)
504+
494505
call assert_fails("call deepcopy([1, 2], 2)", 'E1023:')
495506
endfunc
496507

497508
" Locked variables
498509
func Test_list_locked_var()
499-
let expected = [
500-
\ [['1000-000', 'ppppppF'],
501-
\ ['0000-000', 'ppppppp'],
502-
\ ['0000-000', 'ppppppp']],
503-
\ [['1000-000', 'ppppppF'],
504-
\ ['0000-000', 'ppppppp'],
505-
\ ['0000-000', 'ppppppp']],
506-
\ [['1100-100', 'ppFppFF'],
507-
\ ['0000-000', 'ppppppp'],
508-
\ ['0000-000', 'ppppppp']],
509-
\ [['1110-110', 'pFFpFFF'],
510-
\ ['0010-010', 'pFppFpp'],
511-
\ ['0000-000', 'ppppppp']],
512-
\ [['1111-111', 'FFFFFFF'],
513-
\ ['0011-011', 'FFpFFpp'],
514-
\ ['0000-000', 'ppppppp']]
515-
\ ]
516-
for depth in range(5)
517-
for u in range(3)
518-
unlet! l
519-
let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]
520-
exe "lockvar " . depth . " l"
521-
if u == 1
522-
exe "unlockvar l"
523-
elseif u == 2
524-
exe "unlockvar " . depth . " l"
525-
endif
526-
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]")
527-
call assert_equal(expected[depth][u][0], ps, 'depth: ' .. depth)
528-
let ps = ''
529-
try
530-
let l[1][1][0] = 99
531-
let ps .= 'p'
532-
catch
533-
let ps .= 'F'
534-
endtry
535-
try
536-
let l[1][1] = [99]
537-
let ps .= 'p'
538-
catch
539-
let ps .= 'F'
540-
endtry
541-
try
542-
let l[1] = [99]
543-
let ps .= 'p'
544-
catch
545-
let ps .= 'F'
546-
endtry
547-
try
548-
let l[2]['6'][7] = 99
549-
let ps .= 'p'
550-
catch
551-
let ps .= 'F'
552-
endtry
553-
try
554-
let l[2][6] = {99: 99}
555-
let ps .= 'p'
556-
catch
557-
let ps .= 'F'
558-
endtry
559-
try
560-
let l[2] = {99: 99}
561-
let ps .= 'p'
562-
catch
563-
let ps .= 'F'
564-
endtry
565-
try
566-
let l = [99]
567-
let ps .= 'p'
568-
catch
569-
let ps .= 'F'
570-
endtry
571-
call assert_equal(expected[depth][u][1], ps, 'depth: ' .. depth)
572-
endfor
573-
endfor
510+
" Not tested with :def function, local vars cannot be locked.
511+
let lines =<< trim END
512+
VAR expected = [
513+
\ [['1000-000', 'ppppppF'],
514+
\ ['0000-000', 'ppppppp'],
515+
\ ['0000-000', 'ppppppp']],
516+
\ [['1000-000', 'ppppppF'],
517+
\ ['0000-000', 'ppppppp'],
518+
\ ['0000-000', 'ppppppp']],
519+
\ [['1100-100', 'ppFppFF'],
520+
\ ['0000-000', 'ppppppp'],
521+
\ ['0000-000', 'ppppppp']],
522+
\ [['1110-110', 'pFFpFFF'],
523+
\ ['0010-010', 'pFppFpp'],
524+
\ ['0000-000', 'ppppppp']],
525+
\ [['1111-111', 'FFFFFFF'],
526+
\ ['0011-011', 'FFpFFpp'],
527+
\ ['0000-000', 'ppppppp']]
528+
\ ]
529+
for depth in range(5)
530+
for u in range(3)
531+
VAR l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]
532+
exe "lockvar " .. depth .. " l"
533+
if u == 1
534+
exe "unlockvar l"
535+
elseif u == 2
536+
exe "unlockvar " .. depth .. " l"
537+
endif
538+
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]")
539+
call assert_equal(expected[depth][u][0], ps, 'depth: ' .. depth)
540+
LET ps = ''
541+
try
542+
LET l[1][1][0] = 99
543+
LET ps ..= 'p'
544+
catch
545+
LET ps ..= 'F'
546+
endtry
547+
try
548+
LET l[1][1] = [99]
549+
LET ps ..= 'p'
550+
catch
551+
LET ps ..= 'F'
552+
endtry
553+
try
554+
LET l[1] = [99]
555+
LET ps ..= 'p'
556+
catch
557+
LET ps ..= 'F'
558+
endtry
559+
try
560+
LET l[2]['6'][7] = 99
561+
LET ps ..= 'p'
562+
catch
563+
LET ps ..= 'F'
564+
endtry
565+
try
566+
LET l[2][6] = {99: 99}
567+
LET ps ..= 'p'
568+
catch
569+
LET ps ..= 'F'
570+
endtry
571+
try
572+
LET l[2] = {99: 99}
573+
LET ps ..= 'p'
574+
catch
575+
LET ps ..= 'F'
576+
endtry
577+
try
578+
LET l = [99]
579+
LET ps ..= 'p'
580+
catch
581+
LET ps ..= 'F'
582+
endtry
583+
call assert_equal(expected[depth][u][1], ps, 'depth: ' .. depth)
584+
unlock! l
585+
endfor
586+
endfor
587+
END
588+
call CheckTransLegacySuccess(lines)
589+
call CheckTransVim9Success(lines)
590+
574591
call assert_fails("let x=islocked('a b')", 'E488:')
575592
let mylist = [1, 2, 3]
576593
call assert_fails("let x = islocked('mylist[1:2]')", 'E786:')
@@ -580,6 +597,7 @@ endfunc
580597

581598
" Unletting locked variables
582599
func Test_list_locked_var_unlet()
600+
" Not tested with Vim9: script and local variables cannot be unlocked
583601
let expected = [
584602
\ [['1000-000', 'ppppppp'],
585603
\ ['0000-000', 'ppppppp'],
@@ -674,26 +692,43 @@ endfunc
674692

675693
" unlet after lock on dict item
676694
func Test_dict_item_lock_unlet()
677-
let d = {'a': 99, 'b': 100}
678-
lockvar d.a
679-
unlet d.a
680-
call assert_equal({'b' : 100}, d)
695+
let lines =<< trim END
696+
VAR d = {'a': 99, 'b': 100}
697+
lockvar d.a
698+
unlet d.a
699+
call assert_equal({'b': 100}, d)
700+
END
701+
" TODO: make this work in a :def function
702+
"call CheckLegacyAndVim9Success(lines)
703+
call CheckTransLegacySuccess(lines)
704+
call CheckTransVim9Success(lines)
681705
endfunc
682706

683707
" filter() after lock on dict item
684708
func Test_dict_lock_filter()
685-
let d = {'a': 99, 'b': 100}
686-
lockvar d.a
687-
call filter(d, 'v:key != "a"')
688-
call assert_equal({'b' : 100}, d)
709+
let lines =<< trim END
710+
VAR d = {'a': 99, 'b': 100}
711+
lockvar d.a
712+
call filter(d, 'v:key != "a"')
713+
call assert_equal({'b': 100}, d)
714+
END
715+
" TODO: make this work in a :def function
716+
"call CheckLegacyAndVim9Success(lines)
717+
call CheckTransLegacySuccess(lines)
718+
call CheckTransVim9Success(lines)
689719
endfunc
690720

691721
" map() after lock on dict
692722
func Test_dict_lock_map()
693-
let d = {'a': 99, 'b': 100}
694-
lockvar 1 d
695-
call map(d, 'v:val + 200')
696-
call assert_equal({'a' : 299, 'b' : 300}, d)
723+
let lines =<< trim END
724+
VAR d = {'a': 99, 'b': 100}
725+
lockvar 1 d
726+
call map(d, 'v:val + 200')
727+
call assert_equal({'a': 299, 'b': 300}, d)
728+
END
729+
" This won't work in a :def function
730+
call CheckTransLegacySuccess(lines)
731+
call CheckTransVim9Success(lines)
697732
endfunc
698733

699734
" No extend() after lock on dict item

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3334,
758760
/**/
759761
3333,
760762
/**/

src/vim9compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7433,7 +7433,7 @@ compile_lock_unlock(
74337433
// Cannot use :lockvar and :unlockvar on local variables.
74347434
if (p[1] != ':')
74357435
{
7436-
char_u *end = skip_var_one(p, FALSE);
7436+
char_u *end = find_name_end(p, NULL, NULL, FNE_CHECK_START);
74377437

74387438
if (lookup_local(p, end - p, NULL, cctx) == OK)
74397439
{

0 commit comments

Comments
 (0)