diff src/testdir/test_vim9_builtin.vim @ 22766:a7082e865ffd v8.2.1931

patch 8.2.1931: Vim9: arguments of extend() not checked at compile time Commit: https://github.com/vim/vim/commit/fbcbffe1ad327f4f0da518abfd5fd7be7fec22b5 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 31 19:33:38 2020 +0100 patch 8.2.1931: Vim9: arguments of extend() not checked at compile time Problem: Vim9: arguments of extend() not checked at compile time. Solution: Add argument type checking for extend().
author Bram Moolenaar <Bram@vim.org>
date Sat, 31 Oct 2020 19:45:03 +0100
parents 9fa3f92248f6
children a8bccb0634bc
line wrap: on
line diff
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -191,6 +191,24 @@ def Test_expand()
   close
 enddef
 
+def Test_extend_arg_types()
+  assert_equal([1, 2, 3], extend([1, 2], [3]))
+  assert_equal([3, 1, 2], extend([1, 2], [3], 0))
+  assert_equal([1, 3, 2], extend([1, 2], [3], 1))
+
+  assert_equal(#{a: 1, b: 2, c: 3}, extend(#{a: 1, b: 2}, #{c: 3}))
+  assert_equal(#{a: 1, b: 4}, extend(#{a: 1, b: 2}, #{b: 4}))
+  assert_equal(#{a: 1, b: 2}, extend(#{a: 1, b: 2}, #{b: 4}, 'keep'))
+
+  CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
+  CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
+  CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
+
+  CheckDefFailure(['extend(#{a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
+  CheckDefFailure(['extend(#{a: 1}, #{b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>')
+  CheckDefFailure(['extend(#{a: 1}, #{b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
+enddef
+
 def Test_extend_return_type()
   var l = extend([1, 2], [3])
   var res = 0