forked from aniani/vim
patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Problem: Vim9: unpack assignment using "_" after semicolon fails. Solution: Drop the expression result. (closes #8453)
This commit is contained in:
@@ -318,7 +318,7 @@ EXTERN char e_using_bool_as_number[]
|
||||
EXTERN char e_missing_matching_bracket_after_dict_key[]
|
||||
INIT(= N_("E1139: Missing matching bracket after dict key"));
|
||||
EXTERN char e_for_argument_must_be_sequence_of_lists[]
|
||||
INIT(= N_("E1140: For argument must be a sequence of lists"));
|
||||
INIT(= N_("E1140: :for argument must be a sequence of lists"));
|
||||
EXTERN char e_indexable_type_required[]
|
||||
INIT(= N_("E1141: Indexable type required"));
|
||||
EXTERN char e_non_empty_string_required[]
|
||||
|
@@ -289,6 +289,16 @@ def Test_assign_unpack()
|
||||
assert_equal(1, v1)
|
||||
assert_equal(2, v2)
|
||||
|
||||
var reslist = []
|
||||
for text in ['aaa {bbb} ccc', 'ddd {eee} fff']
|
||||
var before: string
|
||||
var middle: string
|
||||
var after: string
|
||||
[_, before, middle, after; _] = text->matchlist('\(.\{-\}\){\(.\{-\}\)}\(.*\)')
|
||||
reslist->add(before)->add(middle)->add(after)
|
||||
endfor
|
||||
assert_equal(['aaa ', 'bbb', ' ccc', 'ddd ', 'eee', ' fff'], reslist)
|
||||
|
||||
var a = 1
|
||||
var b = 3
|
||||
[a, b] += [2, 4]
|
||||
|
@@ -755,6 +755,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
3054,
|
||||
/**/
|
||||
3053,
|
||||
/**/
|
||||
|
@@ -6598,6 +6598,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
||||
int var_count = 0;
|
||||
int var_idx;
|
||||
int semicolon = 0;
|
||||
int did_generate_slice = FALSE;
|
||||
garray_T *instr = &cctx->ctx_instr;
|
||||
garray_T *stack = &cctx->ctx_type_stack;
|
||||
char_u *op;
|
||||
@@ -6801,6 +6802,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
||||
else if (semicolon && var_idx == var_count - 1)
|
||||
{
|
||||
// For "[var; var] = expr" get the rest of the list
|
||||
did_generate_slice = TRUE;
|
||||
if (generate_SLICE(cctx, var_count - 1) == FAIL)
|
||||
goto theend;
|
||||
}
|
||||
@@ -7010,8 +7012,9 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
||||
var_start = skipwhite(lhs.lhs_dest_end + 1);
|
||||
}
|
||||
|
||||
// for "[var, var] = expr" drop the "expr" value
|
||||
if (var_count > 0 && !semicolon)
|
||||
// For "[var, var] = expr" drop the "expr" value.
|
||||
// Also for "[var, var; _] = expr".
|
||||
if (var_count > 0 && (!semicolon || !did_generate_slice))
|
||||
{
|
||||
if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL)
|
||||
goto theend;
|
||||
|
Reference in New Issue
Block a user