patch 8.2.3997: Vim9: not enough testing for extend() and map()
Problem: Vim9: not enough testing for extend() and map().
Solution: Add more test cases. Fix uncovered problems. Remove unused type
fields.
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index d957c15..eb86a03 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -979,6 +979,10 @@
var res: list<dict<any>>
extend(res, mapnew([1, 2], (_, v) => ({})))
assert_equal([{}, {}], res)
+
+ var dany: dict<any> = {a: 0}
+ dany->extend({b: 'x'})
+ assert_equal({a: 0, b: 'x'}, dany)
END
CheckDefAndScriptSuccess(lines)
@@ -2151,9 +2155,29 @@
CheckDefAndScriptFailure(['map(1, "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got number', 'E1251: List, Dictionary, Blob or String required for argument 1'])
# type of dict remains dict<any> even when type of values changes
- var d: dict<any> = {a: 0}
- d->map((k, v) => true)
- d->map((k, v) => 'x')
+ # same for list
+ var lines =<< trim END
+ var d: dict<any> = {a: 0}
+ d->map((k, v) => true)
+ d->map((k, v) => 'x')
+ assert_equal({a: 'x'}, d)
+
+ d = {a: 0}
+ g:gd = d
+ map(g:gd, (k, v) => true)
+ assert_equal({a: true}, g:gd)
+
+ var l: list<any> = [0]
+ l->map((k, v) => true)
+ l->map((k, v) => 'x')
+ assert_equal(['x'], l)
+
+ l = [1]
+ g:gl = l
+ map(g:gl, (k, v) => true)
+ assert_equal([true], g:gl)
+ END
+ CheckDefAndScriptSuccess(lines)
enddef
def Test_map_failure()
@@ -2175,6 +2199,13 @@
CheckScriptFailure(lines, 'E1013:')
au! BufReadPost
delete('Xtmpfile')
+
+ lines =<< trim END
+ var d: dict<number> = {a: 1}
+ g:gd = d
+ map(g:gd, (k, v) => true)
+ END
+ CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got bool')
enddef
def Test_map_function_arg()
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim
index d4a5309..3a7642f 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -455,6 +455,7 @@
'\d\+ CHECKTYPE string stack\[-1\] arg 2\_s*' ..
'\d\+ STORE $1\_s*' ..
'\d\+ SLICE 2\_s*' ..
+ '\d\+ SETTYPE list<any>\_s*' ..
'\d\+ STORE $2\_s*' ..
'\d\+ RETURN void',
res)