Skip to content

Commit 918a424

Browse files
committed
patch 8.2.2099: Vim9: some checks are not tested
Problem: Vim9: some checks are not tested. Solution: Add a few more tests. Give better error messages.
1 parent 08cf0c0 commit 918a424

4 files changed

Lines changed: 94 additions & 7 deletions

File tree

src/testdir/test_vim9_expr.vim

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ func Test_expr1_trinary_fails()
188188
call CheckDefExecFailure(["var x = [] ? 'one' : 'two'"], 'E745:', 1)
189189
call CheckDefExecFailure(["var x = {} ? 'one' : 'two'"], 'E728:', 1)
190190

191+
call CheckDefExecFailure(["var x = false ? "], 'E1097:', 2)
192+
call CheckDefExecFailure(["var x = false ? 'one' : "], 'E1097:', 2)
193+
194+
call CheckDefExecFailure(["var x = true ? xxx : 'foo'"], 'E1001:', 1)
195+
call CheckDefExecFailure(["var x = false ? 'foo' : xxx"], 'E1001:', 1)
196+
191197
if has('float')
192198
call CheckDefFailure(["var x = 0.1 ? 'one' : 'two'"], 'E805:', 1)
193199
endif
@@ -346,6 +352,8 @@ def Test_expr2_fails()
346352
call CheckDefFailure(["var x = 1 ||2"], msg, 1)
347353
call CheckDefFailure(["var x = 1|| 2"], msg, 1)
348354

355+
call CheckDefFailure(["var x = false || "], 'E1097:', 2)
356+
349357
call CheckDefFailure(["var x = 1 || xxx"], 'E1001:', 1)
350358
call CheckDefFailure(["var x = [] || false"], 'E1012:', 1)
351359
call CheckDefFailure(["if 'yes' || 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 1)
@@ -579,6 +587,8 @@ def Test_expr4_equal()
579587
CheckDefAndScriptSuccess(lines)
580588

581589
CheckDefFailure(["var x = 'a' == xxx"], 'E1001:', 1)
590+
CheckDefFailure(["var x = 'a' == "], 'E1097:', 2)
591+
582592
CheckDefExecFailure(['var items: any', 'eval 1', 'eval 2', 'if items == []', 'endif'], 'E691:', 4)
583593
enddef
584594

@@ -1349,6 +1359,7 @@ def Test_expr6()
13491359
CheckDefAndScriptSuccess(lines)
13501360

13511361
CheckDefFailure(["var x = 6 * xxx"], 'E1001:', 1)
1362+
CheckDefFailure(["var d = 6 * "], 'E1097:', 2)
13521363
enddef
13531364

13541365
def Test_expr6_vim9script()
@@ -1520,6 +1531,7 @@ def Test_expr7t()
15201531
assert_equal(234, nr)
15211532

15221533
CheckDefFailure(["var x = <nr>123"], 'E1010:', 1)
1534+
CheckDefFailure(["var x = <number>"], 'E1097:', 2)
15231535
CheckDefFailure(["var x = <number >123"], 'E1068:', 1)
15241536
CheckDefFailure(["var x = <number 123"], 'E1104:', 1)
15251537
enddef
@@ -2052,6 +2064,33 @@ def Test_expr7_dict_vim9script()
20522064
END
20532065
CheckScriptFailure(lines, 'E1012:', 2)
20542066

2067+
lines =<< trim END
2068+
vim9script
2069+
var d = {['a']: 234, ['b': 'x'}
2070+
END
2071+
CheckScriptFailure(lines, 'E1139:', 2)
2072+
lines =<< trim END
2073+
vim9script
2074+
def Func()
2075+
var d = {['a']: 234, ['b': 'x'}
2076+
enddef
2077+
defcompile
2078+
END
2079+
CheckScriptFailure(lines, 'E1139:', 1)
2080+
lines =<< trim END
2081+
vim9script
2082+
var d = {'a':
2083+
END
2084+
CheckScriptFailure(lines, 'E15:', 2)
2085+
lines =<< trim END
2086+
vim9script
2087+
def Func()
2088+
var d = {'a':
2089+
enddef
2090+
defcompile
2091+
END
2092+
CheckScriptFailure(lines, 'E723:', 1)
2093+
20552094
lines =<< trim END
20562095
vim9script
20572096
def Failing()
@@ -2566,6 +2605,39 @@ def Test_expr7_string_subscript()
25662605
END
25672606
CheckDefSuccess(lines)
25682607
CheckScriptSuccess(['vim9script'] + lines)
2608+
2609+
lines =<< trim END
2610+
var d = 'asdf'[1:
2611+
END
2612+
CheckDefFailure(lines, 'E1097:', 2)
2613+
lines =<< trim END
2614+
var d = 'asdf'[1:xxx]
2615+
END
2616+
CheckDefFailure(lines, 'E1001:', 1)
2617+
lines =<< trim END
2618+
var d = 'asdf'[1:2
2619+
END
2620+
CheckDefFailure(lines, 'E1097:', 2)
2621+
lines =<< trim END
2622+
var d = 'asdf'[1:2
2623+
echo d
2624+
END
2625+
CheckDefFailure(lines, 'E111:', 2)
2626+
lines =<< trim END
2627+
var d = 'asdf'['1']
2628+
echo d
2629+
END
2630+
CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
2631+
lines =<< trim END
2632+
var d = 'asdf'['1':2]
2633+
echo d
2634+
END
2635+
CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
2636+
lines =<< trim END
2637+
var d = 'asdf'[1:'2']
2638+
echo d
2639+
END
2640+
CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
25692641
enddef
25702642

25712643
def Test_expr7_list_subscript()

src/testdir/test_vim9_script.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,18 @@ def Test_vim9_import_export()
962962
writefile(import_already_defined, 'Ximport.vim')
963963
assert_fails('source Ximport.vim', 'E1073:', '', 3, 'Ximport.vim')
964964

965+
# try changing an imported const
966+
var import_assign_to_const =<< trim END
967+
vim9script
968+
import CONST from './Xexport.vim'
969+
def Assign()
970+
CONST = 987
971+
enddef
972+
defcompile
973+
END
974+
writefile(import_assign_to_const, 'Ximport.vim')
975+
assert_fails('source Ximport.vim', 'E46:', '', 1, '_Assign')
976+
965977
# import a very long name, requires making a copy
966978
var import_long_name_lines =<< trim END
967979
vim9script

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2099,
753755
/**/
754756
2098,
755757
/**/

src/vim9compile.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,8 @@ compile_load(
25032503
case 'w': isn_type = ISN_LOADW; break;
25042504
case 't': isn_type = ISN_LOADT; break;
25052505
case 'b': isn_type = ISN_LOADB; break;
2506-
default: semsg(_(e_namespace_not_supported_str), *arg);
2506+
default: // cannot happen, just in case
2507+
semsg(_(e_namespace_not_supported_str), *arg);
25072508
goto theend;
25082509
}
25092510
if (isn_type != ISN_DROP)
@@ -3581,7 +3582,7 @@ compile_subscript(
35813582
else
35823583
{
35833584
if (compile_expr0(arg, cctx) == FAIL)
3584-
return FAIL;
3585+
return FAIL;
35853586
if (may_get_next_line_error(p, arg, cctx) == FAIL)
35863587
return FAIL;
35873588
*arg = skipwhite(*arg);
@@ -4084,7 +4085,7 @@ compile_expr6(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
40844085
return FAIL;
40854086
}
40864087
*arg = skipwhite(op + 1);
4087-
if (may_get_next_line(op + 1, arg, cctx) == FAIL)
4088+
if (may_get_next_line_error(op + 1, arg, cctx) == FAIL)
40884089
return FAIL;
40894090

40904091
// get the second expression
@@ -4291,7 +4292,7 @@ compile_expr4(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
42914292

42924293
// get the second variable
42934294
*arg = skipwhite(p + len);
4294-
if (may_get_next_line(p + len, arg, cctx) == FAIL)
4295+
if (may_get_next_line_error(p + len, arg, cctx) == FAIL)
42954296
return FAIL;
42964297

42974298
if (compile_expr5(arg, cctx, ppconst) == FAIL)
@@ -4390,7 +4391,7 @@ compile_and_or(
43904391

43914392
// eval the next expression
43924393
*arg = skipwhite(p + 2);
4393-
if (may_get_next_line(p + 2, arg, cctx) == FAIL)
4394+
if (may_get_next_line_error(p + 2, arg, cctx) == FAIL)
43944395
return FAIL;
43954396

43964397
if ((opchar == '|' ? compile_expr3(arg, cctx, ppconst)
@@ -4584,7 +4585,7 @@ compile_expr1(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
45844585

45854586
// evaluate the second expression; any type is accepted
45864587
*arg = skipwhite(p + 1 + op_falsy);
4587-
if (may_get_next_line(p + 1 + op_falsy, arg, cctx) == FAIL)
4588+
if (may_get_next_line_error(p + 1 + op_falsy, arg, cctx) == FAIL)
45884589
return FAIL;
45894590
if (compile_expr1(arg, cctx, ppconst) == FAIL)
45904591
return FAIL;
@@ -4634,7 +4635,7 @@ compile_expr1(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
46344635
cctx->ctx_skip = save_skip == SKIP_YES || const_value
46354636
? SKIP_YES : SKIP_NOT;
46364637
*arg = skipwhite(p + 1);
4637-
if (may_get_next_line(p + 1, arg, cctx) == FAIL)
4638+
if (may_get_next_line_error(p + 1, arg, cctx) == FAIL)
46384639
return FAIL;
46394640
if (compile_expr1(arg, cctx, ppconst) == FAIL)
46404641
return FAIL;

0 commit comments

Comments
 (0)