Skip to content

Commit 33fa29c

Browse files
committed
patch 8.2.0467: Vim9: some errors are not tested
Problem: Vim9: some errors are not tested Solution: Add more tests. Fix that Vim9 script flag is not reset.
1 parent 09c5690 commit 33fa29c

6 files changed

Lines changed: 61 additions & 7 deletions

File tree

src/dict.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ eval_dict(char_u **arg, typval_T *rettv, int evaluate, int literal)
826826

827827
if (**arg != ':')
828828
{
829-
semsg(_(e_missing_dict_colon), *arg);
829+
if (evaluate)
830+
semsg(_(e_missing_dict_colon), *arg);
830831
clear_tv(&tvkey);
831832
goto failret;
832833
}
@@ -853,7 +854,8 @@ eval_dict(char_u **arg, typval_T *rettv, int evaluate, int literal)
853854
item = dict_find(d, key, -1);
854855
if (item != NULL)
855856
{
856-
semsg(_(e_duplicate_key), key);
857+
if (evaluate)
858+
semsg(_(e_duplicate_key), key);
857859
clear_tv(&tvkey);
858860
clear_tv(&tv);
859861
goto failret;
@@ -873,15 +875,17 @@ eval_dict(char_u **arg, typval_T *rettv, int evaluate, int literal)
873875
break;
874876
if (**arg != ',')
875877
{
876-
semsg(_(e_missing_dict_comma), *arg);
878+
if (evaluate)
879+
semsg(_(e_missing_dict_comma), *arg);
877880
goto failret;
878881
}
879882
*arg = skipwhite(*arg + 1);
880883
}
881884

882885
if (**arg != '}')
883886
{
884-
semsg(_(e_missing_dict_end), *arg);
887+
if (evaluate)
888+
semsg(_(e_missing_dict_end), *arg);
885889
failret:
886890
if (d != NULL)
887891
dict_free(d);

src/scriptfile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,7 @@ do_source(
12741274

12751275
// loading the same script again
12761276
si->sn_had_command = FALSE;
1277+
si->sn_version = 1;
12771278
current_sctx.sc_sid = sid;
12781279

12791280
ht = &SCRIPT_VARS(sid);

src/testdir/test_vim9_expr.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,12 +812,25 @@ func Test_expr7_fails()
812812
call CheckDefExecFailure("echo s:doesnt_exist", 'E121:')
813813
call CheckDefExecFailure("echo g:doesnt_exist", 'E121:')
814814

815+
call CheckDefFailure("echo a:somevar", 'E1075:')
816+
call CheckDefFailure("echo l:somevar", 'E1075:')
817+
call CheckDefFailure("echo x:somevar", 'E1075:')
818+
819+
" TODO
820+
call CheckDefFailure("echo b:somevar", 'not supported yet')
821+
call CheckDefFailure("echo w:somevar", 'not supported yet')
822+
call CheckDefFailure("echo t:somevar", 'not supported yet')
823+
815824
call CheckDefExecFailure("let x = +g:astring", 'E1030:')
816825
call CheckDefExecFailure("let x = +g:ablob", 'E974:')
817826
call CheckDefExecFailure("let x = +g:alist", 'E745:')
818827
call CheckDefExecFailure("let x = +g:adict", 'E728:')
819828

820829
call CheckDefFailureMult(["let x = ''", "let y = x.memb"], 'E715:')
830+
831+
call CheckDefExecFailure("[1, 2->len()", 'E492:')
832+
call CheckDefExecFailure("#{a: 1->len()", 'E488:')
833+
call CheckDefExecFailure("{'a': 1->len()", 'E492:')
821834
endfunc
822835

823836
let g:Funcrefs = [function('add')]
@@ -878,4 +891,8 @@ func Test_expr_fails()
878891
call CheckDefFailure("v:nosuch += 3", 'E1001:')
879892
call CheckDefFailure("let v:version = 3", 'E1064:')
880893
call CheckDefFailure("let asdf = v:nosuch", 'E1001:')
894+
895+
call CheckDefFailure("echo len('asdf'", 'E110:')
896+
call CheckDefFailure("echo Func0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()", 'E1011:')
897+
call CheckDefFailure("echo doesnotexist()", 'E117:')
881898
endfunc

src/testdir/test_vim9_script.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ func Test_assignment_failure()
101101
call CheckDefFailure(['let true = 1'], 'E1034:')
102102
call CheckDefFailure(['let false = 1'], 'E1034:')
103103

104+
call CheckScriptFailure(['vim9script', 'def Func()', 'let dummy = s:notfound', 'enddef'], 'E1050:')
105+
104106
call CheckDefFailure(['let var: list<string> = [123]'], 'expected list<string> but got list<number>')
105107
call CheckDefFailure(['let var: list<number> = ["xx"]'], 'expected list<number> but got list<string>')
106108

@@ -618,6 +620,12 @@ def Test_vim9script_call()
618620
enddef
619621
{'a': 1, 'b': 2}->DictFunc()
620622
assert_equal(#{a: 1, b: 2}, dictvar)
623+
def CompiledDict()
624+
{'a': 3, 'b': 4}->DictFunc()
625+
enddef
626+
CompiledDict()
627+
assert_equal(#{a: 3, b: 4}, dictvar)
628+
621629
#{a: 3, b: 4}->DictFunc()
622630
assert_equal(#{a: 3, b: 4}, dictvar)
623631

src/version.c

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

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
467,
741743
/**/
742744
466,
743745
/**/

src/vim9compile.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,10 @@ compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int error)
18151815
if (*(*arg + 1) == ':')
18161816
{
18171817
// load namespaced variable
1818-
name = vim_strnsave(*arg + 2, end - (*arg + 2));
1818+
if (end <= *arg + 2)
1819+
name = vim_strsave((char_u *)"[empty]");
1820+
else
1821+
name = vim_strnsave(*arg + 2, end - (*arg + 2));
18191822
if (name == NULL)
18201823
return FAIL;
18211824

@@ -1833,9 +1836,24 @@ compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int error)
18331836
{
18341837
res = compile_load_scriptvar(cctx, name, NULL, NULL, error);
18351838
}
1839+
else if (**arg == 'b')
1840+
{
1841+
semsg("Namespace b: not supported yet: %s", *arg);
1842+
goto theend;
1843+
}
1844+
else if (**arg == 'w')
1845+
{
1846+
semsg("Namespace w: not supported yet: %s", *arg);
1847+
goto theend;
1848+
}
1849+
else if (**arg == 't')
1850+
{
1851+
semsg("Namespace t: not supported yet: %s", *arg);
1852+
goto theend;
1853+
}
18361854
else
18371855
{
1838-
semsg("Namespace not supported yet: %s", *arg);
1856+
semsg("E1075: Namespace not supported: %s", *arg);
18391857
goto theend;
18401858
}
18411859
}
@@ -2060,6 +2078,7 @@ to_name_const_end(char_u *arg)
20602078
}
20612079
else if (p == arg && *arg == '#' && arg[1] == '{')
20622080
{
2081+
// Can be "#{a: 1}->Func()".
20632082
++p;
20642083
if (eval_dict(&p, &rettv, FALSE, TRUE) == FAIL)
20652084
p = arg;
@@ -2068,6 +2087,8 @@ to_name_const_end(char_u *arg)
20682087
{
20692088
int ret = get_lambda_tv(&p, &rettv, FALSE);
20702089

2090+
// Can be "{x -> ret}()".
2091+
// Can be "{'a': 1}->Func()".
20712092
if (ret == NOTDONE)
20722093
ret = eval_dict(&p, &rettv, FALSE, FALSE);
20732094
if (ret != OK)
@@ -5123,7 +5144,8 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
51235144
}
51245145

51255146
// "{" starts a block scope
5126-
if (*ea.cmd == '{')
5147+
// "{'a': 1}->func() is something else
5148+
if (*ea.cmd == '{' && ends_excmd(*skipwhite(ea.cmd + 1)))
51275149
{
51285150
line = compile_block(ea.cmd, &cctx);
51295151
continue;

0 commit comments

Comments
 (0)