Skip to content

Commit 5e65423

Browse files
committed
patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Problem: Vim9: list<any> is not accepted where list<number> is expected. Solution: Add functions to allocate and free a type_T, use it in ISN_CHECKTYPE. (closes #6959)
1 parent 8b51b7f commit 5e65423

13 files changed

Lines changed: 258 additions & 154 deletions

src/errors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ EXTERN char e_type_not_recognized_str[]
5252
EXTERN char e_name_too_long_str[]
5353
INIT(= N_("E1011: name too long: %s"));
5454
EXTERN char e_type_mismatch_expected_str_but_got_str[]
55-
INIT(= N_("E1012: type mismatch, expected %s but got %s"));
55+
INIT(= N_("E1012: Type mismatch; expected %s but got %s"));
5656
EXTERN char e_argument_nr_type_mismatch_expected_str_but_got_str[]
5757
INIT(= N_("E1013: argument %d: type mismatch, expected %s but got %s"));
5858
EXTERN char e_invalid_key_str[]

src/evalfunc.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,14 @@ ret_argv(int argcount, type_T **argtypes UNUSED)
386386
static type_T *
387387
ret_remove(int argcount UNUSED, type_T **argtypes)
388388
{
389-
if (argtypes[0]->tt_type == VAR_LIST
390-
|| argtypes[0]->tt_type == VAR_DICT)
391-
return argtypes[0]->tt_member;
392-
if (argtypes[0]->tt_type == VAR_BLOB)
393-
return &t_number;
389+
if (argtypes != NULL)
390+
{
391+
if (argtypes[0]->tt_type == VAR_LIST
392+
|| argtypes[0]->tt_type == VAR_DICT)
393+
return argtypes[0]->tt_member;
394+
if (argtypes[0]->tt_type == VAR_BLOB)
395+
return &t_number;
396+
}
394397
return &t_any;
395398
}
396399

@@ -2915,7 +2918,7 @@ ret_f_function(int argcount, type_T **argtypes)
29152918
{
29162919
if (argcount == 1 && argtypes[0]->tt_type == VAR_STRING)
29172920
return &t_func_any;
2918-
return &t_func_void;
2921+
return &t_func_unknown;
29192922
}
29202923

29212924
/*

src/globals.h

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -391,42 +391,41 @@ EXTERN sctx_T current_sctx INIT4(0, 0, 0, 0);
391391

392392

393393
// Commonly used types.
394-
EXTERN type_T t_unknown INIT6(VAR_UNKNOWN, 0, 0, 0, NULL, NULL);
395-
EXTERN type_T t_any INIT6(VAR_ANY, 0, 0, 0, NULL, NULL);
396-
EXTERN type_T t_void INIT6(VAR_VOID, 0, 0, 0, NULL, NULL);
397-
EXTERN type_T t_bool INIT6(VAR_BOOL, 0, 0, 0, NULL, NULL);
398-
EXTERN type_T t_special INIT6(VAR_SPECIAL, 0, 0, 0, NULL, NULL);
399-
EXTERN type_T t_number INIT6(VAR_NUMBER, 0, 0, 0, NULL, NULL);
400-
EXTERN type_T t_float INIT6(VAR_FLOAT, 0, 0, 0, NULL, NULL);
401-
EXTERN type_T t_string INIT6(VAR_STRING, 0, 0, 0, NULL, NULL);
402-
EXTERN type_T t_blob INIT6(VAR_BLOB, 0, 0, 0, NULL, NULL);
403-
EXTERN type_T t_job INIT6(VAR_JOB, 0, 0, 0, NULL, NULL);
404-
EXTERN type_T t_channel INIT6(VAR_CHANNEL, 0, 0, 0, NULL, NULL);
405-
406-
EXTERN type_T t_func_unknown INIT6(VAR_FUNC, -1, 0, 0, &t_unknown, NULL);
407-
EXTERN type_T t_func_void INIT6(VAR_FUNC, -1, 0, 0, &t_void, NULL);
408-
EXTERN type_T t_func_any INIT6(VAR_FUNC, -1, 0, 0, &t_any, NULL);
409-
EXTERN type_T t_func_number INIT6(VAR_FUNC, -1, 0, 0, &t_number, NULL);
410-
EXTERN type_T t_func_string INIT6(VAR_FUNC, -1, 0, 0, &t_string, NULL);
411-
EXTERN type_T t_func_0_void INIT6(VAR_FUNC, 0, 0, 0, &t_void, NULL);
412-
EXTERN type_T t_func_0_any INIT6(VAR_FUNC, 0, 0, 0, &t_any, NULL);
413-
EXTERN type_T t_func_0_number INIT6(VAR_FUNC, 0, 0, 0, &t_number, NULL);
414-
EXTERN type_T t_func_0_string INIT6(VAR_FUNC, 0, 0, 0, &t_string, NULL);
415-
416-
EXTERN type_T t_list_any INIT6(VAR_LIST, 0, 0, 0, &t_any, NULL);
417-
EXTERN type_T t_dict_any INIT6(VAR_DICT, 0, 0, 0, &t_any, NULL);
418-
EXTERN type_T t_list_empty INIT6(VAR_LIST, 0, 0, 0, &t_unknown, NULL);
419-
EXTERN type_T t_dict_empty INIT6(VAR_DICT, 0, 0, 0, &t_unknown, NULL);
420-
421-
EXTERN type_T t_list_bool INIT6(VAR_LIST, 0, 0, 0, &t_bool, NULL);
422-
EXTERN type_T t_list_number INIT6(VAR_LIST, 0, 0, 0, &t_number, NULL);
423-
EXTERN type_T t_list_string INIT6(VAR_LIST, 0, 0, 0, &t_string, NULL);
424-
EXTERN type_T t_list_dict_any INIT6(VAR_LIST, 0, 0, 0, &t_dict_any, NULL);
425-
426-
EXTERN type_T t_dict_bool INIT6(VAR_DICT, 0, 0, 0, &t_bool, NULL);
427-
EXTERN type_T t_dict_number INIT6(VAR_DICT, 0, 0, 0, &t_number, NULL);
428-
EXTERN type_T t_dict_string INIT6(VAR_DICT, 0, 0, 0, &t_string, NULL);
429-
394+
EXTERN type_T t_unknown INIT6(VAR_UNKNOWN, 0, 0, TTFLAG_STATIC, NULL, NULL);
395+
EXTERN type_T t_any INIT6(VAR_ANY, 0, 0, TTFLAG_STATIC, NULL, NULL);
396+
EXTERN type_T t_void INIT6(VAR_VOID, 0, 0, TTFLAG_STATIC, NULL, NULL);
397+
EXTERN type_T t_bool INIT6(VAR_BOOL, 0, 0, TTFLAG_STATIC, NULL, NULL);
398+
EXTERN type_T t_special INIT6(VAR_SPECIAL, 0, 0, TTFLAG_STATIC, NULL, NULL);
399+
EXTERN type_T t_number INIT6(VAR_NUMBER, 0, 0, TTFLAG_STATIC, NULL, NULL);
400+
EXTERN type_T t_float INIT6(VAR_FLOAT, 0, 0, TTFLAG_STATIC, NULL, NULL);
401+
EXTERN type_T t_string INIT6(VAR_STRING, 0, 0, TTFLAG_STATIC, NULL, NULL);
402+
EXTERN type_T t_blob INIT6(VAR_BLOB, 0, 0, TTFLAG_STATIC, NULL, NULL);
403+
EXTERN type_T t_job INIT6(VAR_JOB, 0, 0, TTFLAG_STATIC, NULL, NULL);
404+
EXTERN type_T t_channel INIT6(VAR_CHANNEL, 0, 0, TTFLAG_STATIC, NULL, NULL);
405+
406+
EXTERN type_T t_func_unknown INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_unknown, NULL);
407+
EXTERN type_T t_func_void INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_void, NULL);
408+
EXTERN type_T t_func_any INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_any, NULL);
409+
EXTERN type_T t_func_number INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_number, NULL);
410+
EXTERN type_T t_func_string INIT6(VAR_FUNC, -1, 0, TTFLAG_STATIC, &t_string, NULL);
411+
EXTERN type_T t_func_0_void INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_void, NULL);
412+
EXTERN type_T t_func_0_any INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_any, NULL);
413+
EXTERN type_T t_func_0_number INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_number, NULL);
414+
EXTERN type_T t_func_0_string INIT6(VAR_FUNC, 0, 0, TTFLAG_STATIC, &t_string, NULL);
415+
416+
EXTERN type_T t_list_any INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_any, NULL);
417+
EXTERN type_T t_dict_any INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_any, NULL);
418+
EXTERN type_T t_list_empty INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_unknown, NULL);
419+
EXTERN type_T t_dict_empty INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_unknown, NULL);
420+
421+
EXTERN type_T t_list_bool INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_bool, NULL);
422+
EXTERN type_T t_list_number INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_number, NULL);
423+
EXTERN type_T t_list_string INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_string, NULL);
424+
EXTERN type_T t_list_dict_any INIT6(VAR_LIST, 0, 0, TTFLAG_STATIC, &t_dict_any, NULL);
425+
426+
EXTERN type_T t_dict_bool INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_bool, NULL);
427+
EXTERN type_T t_dict_number INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_number, NULL);
428+
EXTERN type_T t_dict_string INIT6(VAR_DICT, 0, 0, TTFLAG_STATIC, &t_string, NULL);
430429

431430
#endif
432431

src/proto/vim9type.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* vim9type.c */
2-
type_T *alloc_type(garray_T *type_gap);
2+
type_T *get_type_ptr(garray_T *type_gap);
33
void clear_type_list(garray_T *gap);
4+
type_T *alloc_type(type_T *type);
5+
void free_type(type_T *type);
46
type_T *get_list_type(type_T *member_type, garray_T *type_gap);
57
type_T *get_dict_type(type_T *member_type, garray_T *type_gap);
68
type_T *alloc_func_type(type_T *ret_type, int argcount, garray_T *type_gap);

src/testdir/test_vim9_disassemble.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def Test_disassemble_list_assign()
258258
'\d STORE $2\_s*' ..
259259
'\[x, y; l\] = g:stringlist\_s*' ..
260260
'\d LOADG g:stringlist\_s*' ..
261-
'\d CHECKTYPE list stack\[-1\]\_s*' ..
261+
'\d CHECKTYPE list<any> stack\[-1\]\_s*' ..
262262
'\d CHECKLEN >= 2\_s*' ..
263263
'\d\+ ITEM 0\_s*' ..
264264
'\d\+ CHECKTYPE string stack\[-1\]\_s*' ..
@@ -829,7 +829,7 @@ def Test_disassemble_for_loop_eval()
829829
'\d STORE -1 in $1\_s*' ..
830830
'\d PUSHS "\["one", "two"\]"\_s*' ..
831831
'\d BCALL eval(argc 1)\_s*' ..
832-
'\d CHECKTYPE list stack\[-1\]\_s*' ..
832+
'\d CHECKTYPE list<any> stack\[-1\]\_s*' ..
833833
'\d FOR $1 -> \d\+\_s*' ..
834834
'\d STORE $2\_s*' ..
835835
'res ..= str\_s*' ..
@@ -1144,7 +1144,7 @@ def Test_disassemble_any_slice()
11441144
'\d STORE $0\_s*' ..
11451145
'return res\_s*' ..
11461146
'\d LOAD $0\_s*' ..
1147-
'\d CHECKTYPE list stack\[-1\]\_s*' ..
1147+
'\d CHECKTYPE list<number> stack\[-1\]\_s*' ..
11481148
'\d RETURN',
11491149
instr)
11501150
assert_equal([2, 3, 4], AnySlice())

src/testdir/test_vim9_expr.vim

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,8 +1438,11 @@ def Test_expr7_vimvar()
14381438
let old: list<string> = v:oldfiles
14391439
let compl: dict<any> = v:completed_item
14401440

1441-
CheckDefFailure(["let old: list<number> = v:oldfiles"], 'E1012: type mismatch, expected list<number> but got list<string>', 1)
1442-
CheckDefFailure(["let old: dict<number> = v:completed_item"], 'E1012: type mismatch, expected dict<number> but got dict<any>', 1)
1441+
CheckDefFailure(["let old: list<number> = v:oldfiles"], 'E1012: Type mismatch; expected list<number> but got list<string>', 1)
1442+
new
1443+
exec "normal! afoo fo\<C-N>\<Esc>"
1444+
CheckDefExecFailure(["let old: dict<number> = v:completed_item"], 'E1012: Type mismatch; expected dict<number> but got dict<string>', 1)
1445+
bwipe!
14431446
enddef
14441447

14451448
def Test_expr7_special()
@@ -1520,14 +1523,14 @@ def Test_expr7_list()
15201523

15211524
CheckDefExecFailure(["echo 1", "let x = [][0]", "echo 3"], 'E684:', 2)
15221525

1523-
CheckDefExecFailure(["let x = g:list_mixed['xx']"], 'E1029:', 1)
1526+
CheckDefExecFailure(["let x = g:list_mixed['xx']"], 'E1012:', 1)
15241527
CheckDefFailure(["let x = g:list_mixed["], 'E1097:', 2)
15251528
CheckDefFailure(["let x = g:list_mixed[0"], 'E1097:', 2)
15261529
CheckDefExecFailure(["let x = g:list_empty[3]"], 'E684:', 1)
1527-
CheckDefFailure(["let l: list<number> = [234, 'x']"], 'E1012:', 1)
1528-
CheckDefFailure(["let l: list<number> = ['x', 234]"], 'E1012:', 1)
1529-
CheckDefFailure(["let l: list<string> = [234, 'x']"], 'E1012:', 1)
1530-
CheckDefFailure(["let l: list<string> = ['x', 123]"], 'E1012:', 1)
1530+
CheckDefExecFailure(["let l: list<number> = [234, 'x']"], 'E1012:', 1)
1531+
CheckDefExecFailure(["let l: list<number> = ['x', 234]"], 'E1012:', 1)
1532+
CheckDefExecFailure(["let l: list<string> = [234, 'x']"], 'E1012:', 1)
1533+
CheckDefExecFailure(["let l: list<string> = ['x', 123]"], 'E1012:', 1)
15311534
enddef
15321535

15331536
def Test_expr7_list_vim9script()
@@ -1731,10 +1734,10 @@ def Test_expr7_dict()
17311734
CheckDefExecFailure(["let x = g:anint.member"], 'E715:', 1)
17321735
CheckDefExecFailure(["let x = g:dict_empty.member"], 'E716:', 1)
17331736

1734-
CheckDefFailure(['let x: dict<number> = #{a: 234, b: "1"}'], 'E1012:', 1)
1735-
CheckDefFailure(['let x: dict<number> = #{a: "x", b: 134}'], 'E1012:', 1)
1736-
CheckDefFailure(['let x: dict<string> = #{a: 234, b: "1"}'], 'E1012:', 1)
1737-
CheckDefFailure(['let x: dict<string> = #{a: "x", b: 134}'], 'E1012:', 1)
1737+
CheckDefExecFailure(['let x: dict<number> = #{a: 234, b: "1"}'], 'E1012:', 1)
1738+
CheckDefExecFailure(['let x: dict<number> = #{a: "x", b: 134}'], 'E1012:', 1)
1739+
CheckDefExecFailure(['let x: dict<string> = #{a: 234, b: "1"}'], 'E1012:', 1)
1740+
CheckDefExecFailure(['let x: dict<string> = #{a: "x", b: 134}'], 'E1012:', 1)
17381741
enddef
17391742

17401743
def Test_expr7_dict_vim9script()
@@ -1840,7 +1843,7 @@ def Test_expr_member()
18401843

18411844
CheckDefFailure(["let x = g:dict_one.#$!"], 'E1002:', 1)
18421845
CheckDefExecFailure(["let d: dict<any>", "echo d['a']"], 'E716:', 2)
1843-
CheckDefExecFailure(["let d: dict<number>", "d = g:list_empty"], 'E1029: Expected dict but got list', 2)
1846+
CheckDefExecFailure(["let d: dict<number>", "d = g:list_empty"], 'E1012: Type mismatch; expected dict<number> but got list<unknown>', 2)
18441847
enddef
18451848

18461849
def Test_expr7_any_index_slice()
@@ -2311,7 +2314,7 @@ def Test_expr7_list_subscript()
23112314
CheckScriptSuccess(['vim9script'] + lines)
23122315

23132316
lines = ['let l = [0, 1, 2]', 'echo l[g:astring : g:theone]']
2314-
CheckDefExecFailure(lines, 'E1029:')
2317+
CheckDefExecFailure(lines, 'E1012:')
23152318
CheckScriptFailure(['vim9script'] + lines, 'E1030:', 3)
23162319
enddef
23172320

src/testdir/test_vim9_func.vim

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ enddef
3030
def Test_return_something()
3131
ReturnString()->assert_equal('string')
3232
ReturnNumber()->assert_equal(123)
33-
assert_fails('ReturnGlobal()', 'E1029: Expected number but got string', '', 1, 'ReturnGlobal')
33+
assert_fails('ReturnGlobal()', 'E1012: Type mismatch; expected number but got string', '', 1, 'ReturnGlobal')
3434
enddef
3535

3636
def Test_missing_return()
@@ -487,7 +487,7 @@ def Test_call_funcref()
487487
enddef
488488
let Funcref: func(string) = function('UseNumber')
489489
END
490-
CheckScriptFailure(lines, 'E1012: type mismatch, expected func(string) but got func(number)')
490+
CheckScriptFailure(lines, 'E1012: Type mismatch; expected func(string) but got func(number)')
491491

492492
lines =<< trim END
493493
vim9script
@@ -976,37 +976,37 @@ def Test_func_type_part()
976976
let RefVoid: func: void
977977
RefVoid = FuncNoArgNoRet
978978
RefVoid = FuncOneArgNoRet
979-
CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetNumber'], 'E1012: type mismatch, expected func() but got func(): number')
980-
CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetString'], 'E1012: type mismatch, expected func() but got func(): string')
979+
CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetNumber'], 'E1012: Type mismatch; expected func(...) but got func(): number')
980+
CheckDefFailure(['let RefVoid: func: void', 'RefVoid = FuncNoArgRetString'], 'E1012: Type mismatch; expected func(...) but got func(): string')
981981

982982
let RefAny: func(): any
983983
RefAny = FuncNoArgRetNumber
984984
RefAny = FuncNoArgRetString
985-
CheckDefFailure(['let RefAny: func(): any', 'RefAny = FuncNoArgNoRet'], 'E1012: type mismatch, expected func(): any but got func()')
986-
CheckDefFailure(['let RefAny: func(): any', 'RefAny = FuncOneArgNoRet'], 'E1012: type mismatch, expected func(): any but got func(number)')
985+
CheckDefFailure(['let RefAny: func(): any', 'RefAny = FuncNoArgNoRet'], 'E1012: Type mismatch; expected func(): any but got func()')
986+
CheckDefFailure(['let RefAny: func(): any', 'RefAny = FuncOneArgNoRet'], 'E1012: Type mismatch; expected func(): any but got func(number)')
987987

988988
let RefNr: func: number
989989
RefNr = FuncNoArgRetNumber
990990
RefNr = FuncOneArgRetNumber
991-
CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgNoRet'], 'E1012: type mismatch, expected func(): number but got func()')
992-
CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgRetString'], 'E1012: type mismatch, expected func(): number but got func(): string')
991+
CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgNoRet'], 'E1012: Type mismatch; expected func(...): number but got func()')
992+
CheckDefFailure(['let RefNr: func: number', 'RefNr = FuncNoArgRetString'], 'E1012: Type mismatch; expected func(...): number but got func(): string')
993993

994994
let RefStr: func: string
995995
RefStr = FuncNoArgRetString
996996
RefStr = FuncOneArgRetString
997-
CheckDefFailure(['let RefStr: func: string', 'RefStr = FuncNoArgNoRet'], 'E1012: type mismatch, expected func(): string but got func()')
998-
CheckDefFailure(['let RefStr: func: string', 'RefStr = FuncNoArgRetNumber'], 'E1012: type mismatch, expected func(): string but got func(): number')
997+
CheckDefFailure(['let RefStr: func: string', 'RefStr = FuncNoArgNoRet'], 'E1012: Type mismatch; expected func(...): string but got func()')
998+
CheckDefFailure(['let RefStr: func: string', 'RefStr = FuncNoArgRetNumber'], 'E1012: Type mismatch; expected func(...): string but got func(): number')
999999
enddef
10001000

10011001
def Test_func_type_fails()
10021002
CheckDefFailure(['let ref1: func()'], 'E704:')
10031003

1004-
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncNoArgRetNumber'], 'E1012: type mismatch, expected func() but got func(): number')
1005-
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgNoRet'], 'E1012: type mismatch, expected func() but got func(number)')
1006-
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1012: type mismatch, expected func() but got func(number): number')
1007-
CheckDefFailure(['let Ref1: func(bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1012: type mismatch, expected func(bool) but got func(bool, number)')
1008-
CheckDefFailure(['let Ref1: func(?bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1012: type mismatch, expected func(?bool) but got func(bool, number)')
1009-
CheckDefFailure(['let Ref1: func(...bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1012: type mismatch, expected func(...bool) but got func(bool, number)')
1004+
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncNoArgRetNumber'], 'E1012: Type mismatch; expected func() but got func(): number')
1005+
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgNoRet'], 'E1012: Type mismatch; expected func() but got func(number)')
1006+
CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1012: Type mismatch; expected func() but got func(number): number')
1007+
CheckDefFailure(['let Ref1: func(bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1012: Type mismatch; expected func(bool) but got func(bool, number)')
1008+
CheckDefFailure(['let Ref1: func(?bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1012: Type mismatch; expected func(?bool) but got func(bool, number)')
1009+
CheckDefFailure(['let Ref1: func(...bool)', 'Ref1 = FuncTwoArgNoRet'], 'E1012: Type mismatch; expected func(...bool) but got func(bool, number)')
10101010

10111011
CheckDefFailure(['let RefWrong: func(string ,number)'], 'E1068:')
10121012
CheckDefFailure(['let RefWrong: func(string,number)'], 'E1069:')
@@ -1026,7 +1026,7 @@ def Test_func_return_type()
10261026
str = FuncOneArgRetAny('yes')
10271027
str->assert_equal('yes')
10281028

1029-
CheckDefFailure(['let str: string', 'str = FuncNoArgRetNumber()'], 'E1012: type mismatch, expected string but got number')
1029+
CheckDefFailure(['let str: string', 'str = FuncNoArgRetNumber()'], 'E1012: Type mismatch; expected string but got number')
10301030
enddef
10311031

10321032
def MultiLine(
@@ -1204,7 +1204,7 @@ def ReadRef(Ref: func(): list<string>): string
12041204
return join(Ref(), ' ')
12051205
enddef
12061206

1207-
def ExtendRef(Ref: func(string), add: string)
1207+
def ExtendRef(Ref: func(string): list<string>, add: string)
12081208
Ref(add)
12091209
enddef
12101210

@@ -1408,7 +1408,7 @@ def Wrong_dict_key_type(items: list<number>): list<number>
14081408
enddef
14091409

14101410
def Test_wrong_dict_key_type()
1411-
assert_fails('Wrong_dict_key_type([1, 2, 3])', 'E1029:')
1411+
assert_fails('Wrong_dict_key_type([1, 2, 3])', 'E1012:')
14121412
enddef
14131413

14141414
def Line_continuation_in_def(dir: string = ''): string
@@ -1422,7 +1422,7 @@ def Test_line_continuation_in_def()
14221422
Line_continuation_in_def('.')->assert_equal('full')
14231423
enddef
14241424

1425-
def Line_continuation_in_lambda(): list<number>
1425+
def Line_continuation_in_lambda(): list<string>
14261426
let x = range(97, 100)
14271427
->map({_, v -> nr2char(v)
14281428
->toupper()})

src/testdir/test_vim9_script.vim

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ def Test_assignment()
180180
CheckDefFailure(['&notex += 3'], 'E113:')
181181
CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
182182
CheckDefFailure(['&ts = [7]'], 'E1012:')
183-
CheckDefExecFailure(['&ts = g:alist'], 'E1029: Expected number but got list')
183+
CheckDefExecFailure(['&ts = g:alist'], 'E1012: Type mismatch; expected number but got list<number>')
184184
CheckDefFailure(['&ts = "xx"'], 'E1012:')
185-
CheckDefExecFailure(['&ts = g:astring'], 'E1029: Expected number but got string')
185+
CheckDefExecFailure(['&ts = g:astring'], 'E1012: Type mismatch; expected number but got string')
186186
CheckDefFailure(['&path += 3'], 'E1012:')
187187
CheckDefExecFailure(['&bs = "asdf"'], 'E474:')
188188
# test freeing ISN_STOREOPT
@@ -958,14 +958,14 @@ def Test_try_catch()
958958
try
959959
# string slice returns a string, not a number
960960
n = g:astring[3]
961-
catch /E1029:/
961+
catch /E1012:/
962962
n = 77
963963
endtry
964964
assert_equal(77, n)
965965

966966
try
967967
n = l[g:astring]
968-
catch /E1029:/
968+
catch /E1012:/
969969
n = 88
970970
endtry
971971
assert_equal(88, n)
@@ -1016,7 +1016,7 @@ def Test_try_catch()
10161016
let nd: dict<any>
10171017
try
10181018
nd = {g:anumber: 1}
1019-
catch /E1029:/
1019+
catch /E1012:/
10201020
n = 266
10211021
endtry
10221022
assert_equal(266, n)
@@ -1030,7 +1030,7 @@ def Test_try_catch()
10301030

10311031
try
10321032
&ts = g:astring
1033-
catch /E1029:/
1033+
catch /E1012:/
10341034
n = 288
10351035
endtry
10361036
assert_equal(288, n)
@@ -3184,6 +3184,24 @@ def Test_let_type_check()
31843184
CheckScriptSuccess(lines)
31853185
enddef
31863186

3187+
let g:dict_number = #{one: 1, two: 2}
3188+
3189+
def Test_let_list_dict_type()
3190+
let ll: list<number>
3191+
ll = [1, 2, 2, 3, 3, 3]->uniq()
3192+
ll->assert_equal([1, 2, 3])
3193+
3194+
let dd: dict<number>
3195+
dd = g:dict_number
3196+
dd->assert_equal(g:dict_number)
3197+
3198+
let lines =<< trim END
3199+
let ll: list<number>
3200+
ll = [1, 2, 3]->map('"one"')
3201+
END
3202+
CheckDefExecFailure(lines, 'E1012: Type mismatch; expected list<number> but got list<string>')
3203+
enddef
3204+
31873205
def Test_forward_declaration()
31883206
let lines =<< trim END
31893207
vim9script

0 commit comments

Comments
 (0)