diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-12-25 21:43:28 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-12-25 21:43:28 +0000 |
commit | 1802405d71da20dff510690bf14f6da085836125 (patch) | |
tree | eb17c5e35f51aa31716d3222fd674d77b3629db7 /src/testdir/test_vim9_builtin.vim | |
parent | db8e5c21b98c5998df4ab94e0b94bd9fdaf35c83 (diff) |
patch 8.2.3897: Vim9: second argument of map() and filter() not checkedv8.2.3897
Problem: Vim9: the second argument of map() and filter() is not checked at
compile time.
Solution: Add more specific type check for the second argument.
Diffstat (limited to 'src/testdir/test_vim9_builtin.vim')
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index 547a2132a4..43b9d3373b 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -1241,6 +1241,15 @@ enddef def Test_filter() CheckDefAndScriptFailure(['filter(1.1, "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got float', 'E1251: List, Dictionary, Blob or String required for argument 1']) + + var lines =<< trim END + def F(i: number, v: any): string + return 'bad' + enddef + echo filter([1, 2, 3], F) + END + CheckDefAndScriptFailure(lines, ['E1013: Argument 2: type mismatch, expected func(...): bool', 'E1135: Using a String as a Bool:']) + assert_equal([], filter([1, 2, 3], '0')) assert_equal([1, 2, 3], filter([1, 2, 3], '1')) assert_equal({b: 20}, filter({a: 10, b: 20}, 'v:val == 20')) @@ -2141,6 +2150,14 @@ def Test_map_function_arg() range(3)->map((a, b, c, d) => a + b + c + d) END CheckDefExecAndScriptFailure(lines, 'E1190: 2 arguments too few') + + lines =<< trim END + def Map(i: number, v: number): string + return 'bad' + enddef + echo map([1, 2, 3], Map) + END + CheckDefAndScriptFailure(lines, ['E1013: Argument 2: type mismatch, expected func(...): number but got func(number, number): string', 'E1012: Type mismatch; expected number but got string in map()']) enddef def Test_map_item_type() @@ -2155,19 +2172,19 @@ def Test_map_item_type() var l: list<number> = [0] echo map(l, (_, v) => []) END - CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown> in map()', 2) + CheckDefAndScriptFailure(lines, ['E1013: Argument 2: type mismatch, expected func(...): number but got func(any, any): list<unknown>', 'E1012: Type mismatch; expected number but got list<unknown> in map()'], 2) lines =<< trim END var l: list<number> = range(2) echo map(l, (_, v) => []) END - CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown> in map()', 2) + CheckDefAndScriptFailure(lines, ['E1013: Argument 2: type mismatch, expected func(...): number but got func(any, any): list<unknown>', 'E1012: Type mismatch; expected number but got list<unknown> in map()'], 2) lines =<< trim END var d: dict<number> = {key: 0} echo map(d, (_, v) => []) END - CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown> in map()', 2) + CheckDefAndScriptFailure(lines, ['E1013: Argument 2: type mismatch, expected func(...): number but got func(any, any): list<unknown>', 'E1012: Type mismatch; expected number but got list<unknown> in map()'], 2) enddef def Test_maparg() |