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

patch 8.2.0987: Vim9: cannot assign to [var; var]

Problem:    Vim9: cannot assign to [var; var].
Solution:   Assign rest of items to a list.
This commit is contained in:
Bram Moolenaar
2020-06-16 11:34:42 +02:00
parent c70222d12a
commit 9af78769ee
8 changed files with 161 additions and 17 deletions

View File

@@ -226,9 +226,23 @@ enddef
def Test_assignment_var_list()
let v1: string
let v2: string
let vrem: list<string>
[v1] = ['aaa']
assert_equal('aaa', v1)
[v1, v2] = ['one', 'two']
assert_equal('one', v1)
assert_equal('two', v2)
[v1, v2; vrem] = ['one', 'two']
assert_equal('one', v1)
assert_equal('two', v2)
assert_equal([], vrem)
[v1, v2; vrem] = ['one', 'two', 'three']
assert_equal('one', v1)
assert_equal('two', v2)
assert_equal(['three'], vrem)
enddef
def Mess(): string
@@ -244,7 +258,18 @@ def Test_assignment_failure()
call CheckDefFailure(['let true = 1'], 'E1034:')
call CheckDefFailure(['let false = 1'], 'E1034:')
call CheckDefFailure(['let [a; b; c] = g:list'], 'E452:')
call CheckDefFailure(['[a; b; c] = g:list'], 'E452:')
call CheckDefExecFailure(['let a: number',
'[a] = test_null_list()'], 'E1093:')
call CheckDefExecFailure(['let a: number',
'[a] = []'], 'E1093:')
call CheckDefExecFailure(['let x: number',
'let y: number',
'[x, y] = [1]'], 'E1093:')
call CheckDefExecFailure(['let x: number',
'let y: number',
'let z: list<number>',
'[x, y; z] = [1]'], 'E1093:')
call CheckDefFailure(['let somevar'], "E1022:")
call CheckDefFailure(['let &option'], 'E1052:')