0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

patch 8.2.3064: Vim9: in script cannot set item in uninitialized list

Problem:    Vim9: in script cannot set item in uninitialized list.
Solution:   When a list is NULL allocate an empty one. (closes #8461)
This commit is contained in:
Bram Moolenaar
2021-06-27 15:04:05 +02:00
parent 65aee0b714
commit e65081d1b5
3 changed files with 49 additions and 21 deletions

View File

@@ -1102,21 +1102,30 @@ def Test_assignment_failure()
enddef
def Test_assign_list()
var l: list<string> = []
l[0] = 'value'
assert_equal('value', l[0])
var lines =<< trim END
var l: list<string> = []
l[0] = 'value'
assert_equal('value', l[0])
l[1] = 'asdf'
assert_equal('value', l[0])
assert_equal('asdf', l[1])
assert_equal('asdf', l[-1])
assert_equal('value', l[-2])
l[1] = 'asdf'
assert_equal('value', l[0])
assert_equal('asdf', l[1])
assert_equal('asdf', l[-1])
assert_equal('value', l[-2])
var nrl: list<number> = []
for i in range(5)
nrl[i] = i
endfor
assert_equal([0, 1, 2, 3, 4], nrl)
var nrl: list<number> = []
for i in range(5)
nrl[i] = i
endfor
assert_equal([0, 1, 2, 3, 4], nrl)
var ul: list<any>
ul[0] = 1
ul[1] = 2
ul[2] = 3
assert_equal([1, 2, 3], ul)
END
CheckDefAndScriptSuccess(lines)
CheckDefFailure(["var l: list<number> = ['', true]"], 'E1012: Type mismatch; expected list<number> but got list<any>', 1)
CheckDefFailure(["var l: list<list<number>> = [['', true]]"], 'E1012: Type mismatch; expected list<list<number>> but got list<list<any>>', 1)