@@ -500,17 +500,21 @@ endfunc
500500
501501" No remove() of write-protected scope-level variable
502502func Tfunc1 (this_is_a_long_parameter_name)
503- call assert_fails (" call remove(a:, 'this_is_a_long_parameter_name')" , ' E795 ' )
503+ call assert_fails (" call remove(a:, 'this_is_a_long_parameter_name')" , ' E742 ' )
504504endfunc
505505func Test_dict_scope_var_remove ()
506506 call Tfunc1 (' testval' )
507507endfunc
508508
509509" No extend() of write-protected scope-level variable
510+ func Test_dict_scope_var_extend ()
511+ call assert_fails (" call extend(a:, {'this_is_a_long_parameter_name': 1234})" , ' E742' )
512+ endfunc
513+
510514func Tfunc2 (this_is_a_long_parameter_name)
511515 call assert_fails (" call extend(a:, {'this_is_a_long_parameter_name': 1234})" , ' E742' )
512516endfunc
513- func Test_dict_scope_var_extend ()
517+ func Test_dict_scope_var_extend_overwrite ()
514518 call Tfunc2 (' testval' )
515519endfunc
516520
@@ -651,3 +655,75 @@ func Test_listdict_extend()
651655 call assert_fails (" call extend(d, d, 'error')" , ' E737:' )
652656 call assert_equal ({' a' : {' b' : ' B' }}, d )
653657endfunc
658+
659+ func s: check_scope_dict (x , fixed)
660+ func s: gen_cmd (cmd, x )
661+ return substitute (a: cmd , ' \<x\ze:' , a: x , ' g' )
662+ endfunc
663+
664+ let cmd = s: gen_cmd (' let x:foo = 1' , a: x )
665+ if a: fixed
666+ call assert_fails (cmd, ' E461' )
667+ else
668+ exe cmd
669+ exe s: gen_cmd (' call assert_equal(1, x:foo)' , a: x )
670+ endif
671+
672+ let cmd = s: gen_cmd (' let x:["bar"] = 2' , a: x )
673+ if a: fixed
674+ call assert_fails (cmd, ' E461' )
675+ else
676+ exe cmd
677+ exe s: gen_cmd (' call assert_equal(2, x:bar)' , a: x )
678+ endif
679+
680+ let cmd = s: gen_cmd (' call extend(x:, {"baz": 3})' , a: x )
681+ if a: fixed
682+ call assert_fails (cmd, ' E742' )
683+ else
684+ exe cmd
685+ exe s: gen_cmd (' call assert_equal(3, x:baz)' , a: x )
686+ endif
687+
688+ if a: fixed
689+ if a: x == # ' a'
690+ call assert_fails (' unlet a:x' , ' E795' )
691+ call assert_fails (' call remove(a:, "x")' , ' E742' )
692+ elseif a: x == # ' v'
693+ call assert_fails (' unlet v:count' , ' E795' )
694+ call assert_fails (' call remove(v:, "count")' , ' E742' )
695+ endif
696+ else
697+ exe s: gen_cmd (' unlet x:foo' , a: x )
698+ exe s: gen_cmd (' unlet x:bar' , a: x )
699+ exe s: gen_cmd (' call remove(x:, "baz")' , a: x )
700+ endif
701+
702+ delfunc s: gen_cmd
703+ endfunc
704+
705+ func Test_scope_dict ()
706+ " Test for g:
707+ call s: check_scope_dict (' g' , v: false )
708+
709+ " Test for s:
710+ call s: check_scope_dict (' s' , v: false )
711+
712+ " Test for l:
713+ call s: check_scope_dict (' l' , v: false )
714+
715+ " Test for a:
716+ call s: check_scope_dict (' a' , v: true )
717+
718+ " Test for b:
719+ call s: check_scope_dict (' b' , v: false )
720+
721+ " Test for w:
722+ call s: check_scope_dict (' w' , v: false )
723+
724+ " Test for t:
725+ call s: check_scope_dict (' t' , v: false )
726+
727+ " Test for v:
728+ call s: check_scope_dict (' v' , v: true )
729+ endfunc
0 commit comments