summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_vim9_builtin.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-02-02 20:01:27 +0000
committerBram Moolenaar <Bram@vim.org>2022-02-02 20:01:27 +0000
commit381692b6f1c2ec9b73a139500286ddc9347a1c01 (patch)
tree96145ec58ad29dd86bbc80e557377333c07d059b /src/testdir/test_vim9_builtin.vim
parenta1c519518050383e7d319514a3ff6c42a9154c48 (diff)
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()v8.2.4286
Problem: Vim9: strict type checking after copy() and deepcopy(). Solution: Allow type to change after making a copy. (closes #9644)
Diffstat (limited to 'src/testdir/test_vim9_builtin.vim')
-rw-r--r--src/testdir/test_vim9_builtin.vim25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index 248887f7b0..f7a5006b45 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -720,6 +720,31 @@ def Test_copy_return_type()
res->assert_equal(6)
dl = deepcopy([1, 2, 3], true)
+
+ # after a copy() the type can change, but not the item itself
+ var nl: list<number> = [1, 2]
+ assert_equal([1, 2, 'x'], nl->copy()->extend(['x']))
+
+ var lines =<< trim END
+ var nll: list<list<number>> = [[1, 2]]
+ nll->copy()[0]->extend(['x'])
+ END
+ v9.CheckDefExecAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected list<number> but got list<string> in extend()')
+
+ var nd: dict<number> = {a: 1, b: 2}
+ assert_equal({a: 1, b: 2, c: 'x'}, nd->copy()->extend({c: 'x'}))
+ lines =<< trim END
+ var ndd: dict<dict<number>> = {a: {x: 1, y: 2}}
+ ndd->copy()['a']->extend({z: 'x'})
+ END
+ v9.CheckDefExecAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string> in extend()')
+
+ # after a deepcopy() the item type can also change
+ var nll: list<list<number>> = [[1, 2]]
+ assert_equal([1, 2, 'x'], nll->deepcopy()[0]->extend(['x']))
+
+ var ndd: dict<dict<number>> = {a: {x: 1, y: 2}}
+ assert_equal({x: 1, y: 2, z: 'x'}, ndd->deepcopy()['a']->extend({z: 'x'}))
enddef
def Test_count()