summaryrefslogtreecommitdiff
path: root/src/testdir/test_vim9_builtin.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-02-20 18:26:46 +0000
committerBram Moolenaar <Bram@vim.org>2022-02-20 18:26:46 +0000
commitc1e6c7bafec1115b690c745a28e1a6338750b137 (patch)
tree2299cd11918b10569a201ef2f151afbf4ce4602f /src/testdir/test_vim9_builtin.vim
parenteddd4fc4f6d9d626374a73861c891f95ef999133 (diff)
downloadvim-git-c1e6c7bafec1115b690c745a28e1a6338750b137.tar.gz
patch 8.2.4426: map() function on string and blob does not check typesv8.2.4426
Problem: map() function on string and blob does not check argument types at compile time. Solution: Check string and blob argument types. Support "0z1234->func()".
Diffstat (limited to 'src/testdir/test_vim9_builtin.vim')
-rw-r--r--src/testdir/test_vim9_builtin.vim34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index 882c1811a..41060e1a2 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -2360,13 +2360,33 @@ def Test_maparg()
v9.CheckDefAndScriptFailure(['maparg("a", "b", true, 2)'], ['E1013: Argument 4: type mismatch, expected bool but got number', 'E1212: Bool required for argument 4'])
maparg('')->assert_equal('')
+ # value argument type is checked at compile time
var lines =<< trim END
var l = [123]
- l->map((_, v: string) => 0)
+ l->map((i: number, v: string) => 0)
END
- v9.CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected func(?number, ?number): number but got func(any, string): number')
+ v9.CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected func(?number, ?number): number but got func(number, string): number')
lines =<< trim END
+ var d = {a: 123}
+ d->map((i: string, v: string) => 0)
+ END
+ v9.CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected func(?string, ?number): number but got func(string, string): number')
+
+ lines =<< trim END
+ var s = 'abc'
+ s->map((i: number, v: number) => 'x')
+ END
+ v9.CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected func(?number, ?string): string but got func(number, number): string')
+
+ lines =<< trim END
+ var s = 0z1122
+ s->map((i: number, v: string) => 0)
+ END
+ v9.CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected func(?number, ?number): number but got func(number, string): number')
+
+ # index argument type is checked at compile time
+ lines =<< trim END
['x']->map((i: string, v: string) => 'y')
END
v9.CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected func(?number, ?any): any but got func(string, string): string')
@@ -2375,6 +2395,16 @@ def Test_maparg()
{a: 1}->map((i: number, v: number) => 0)
END
v9.CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected func(?string, ?any): any but got func(number, number): number')
+
+ lines =<< trim END
+ 'abc'->map((i: string, v: string) => 'x')
+ END
+ v9.CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected func(?number, ?string): string but got func(string, string): string')
+
+ lines =<< trim END
+ 0z1122->map((i: string, v: number) => 0)
+ END
+ v9.CheckDefFailure(lines, 'E1013: Argument 2: type mismatch, expected func(?number, ?number): number but got func(string, number): number')
enddef
def Test_maparg_mapset()