patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Problem: Vim9: it is not possible to extend a dictionary with different
item types.
Solution: Add extendnew(). (closes #7666)
diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim
index 762a517..051a37c 100644
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -864,6 +864,18 @@
call assert_fails("call extend(g:, {'-!' : 10})", 'E461:')
endfunc
+func Test_listdict_extendnew()
+ " Test extendnew() with lists
+ let l = [1, 2, 3]
+ call assert_equal([1, 2, 3, 4, 5], extendnew(l, [4, 5]))
+ call assert_equal([1, 2, 3], l)
+
+ " Test extend() with dictionaries.
+ let d = {'a': {'b': 'B'}}
+ call assert_equal({'a': {'b': 'B'}, 'c': 'cc'}, extendnew(d, {'c': 'cc'}))
+ call assert_equal({'a': {'b': 'B'}}, d)
+endfunc
+
func s:check_scope_dict(x, fixed)
func s:gen_cmd(cmd, x)
return substitute(a:cmd, '\<x\ze:', a:x, 'g')
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index 673f0c0..c867266 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -243,6 +243,16 @@
CheckDefFailure(['extend({a: 1}, {b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
enddef
+def Test_extendnew()
+ assert_equal([1, 2, 'a'], extendnew([1, 2], ['a']))
+ assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'}))
+
+ CheckDefFailure(['extendnew({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
+ CheckDefFailure(['extendnew({a: 1}, [42])'], 'E1013: Argument 2: type mismatch, expected dict<number> but got list<number>')
+ CheckDefFailure(['extendnew([1, 2], "x")'], 'E1013: Argument 2: type mismatch, expected list<number> but got string')
+ CheckDefFailure(['extendnew([1, 2], {x: 1})'], 'E1013: Argument 2: type mismatch, expected list<number> but got dict<number>')
+enddef
+
def Test_extend_return_type()
var l = extend([1, 2], [3])
var res = 0