mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2722: Vim9: crash when using LHS with double index
Problem: Vim9: crash when using LHS with double index. Solution: Handle lhs_dest which is "dest_expr". (closes #8068) Fix confusing error message for missing dict item.
This commit is contained in:
@@ -1474,7 +1474,7 @@ set_var_lval(
|
|||||||
{
|
{
|
||||||
if (op != NULL && *op != '=')
|
if (op != NULL && *op != '=')
|
||||||
{
|
{
|
||||||
semsg(_(e_letwrong), op);
|
semsg(_(e_dictkey), lp->ll_newkey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1146,6 +1146,12 @@ def Test_assign_dict_with_op()
|
|||||||
assert_equal(2, dn.a)
|
assert_equal(2, dn.a)
|
||||||
dn.a %= 6
|
dn.a %= 6
|
||||||
assert_equal(2, dn.a)
|
assert_equal(2, dn.a)
|
||||||
|
|
||||||
|
var dd: dict<dict<list<any>>>
|
||||||
|
dd.a = {}
|
||||||
|
dd.a.b = [0]
|
||||||
|
dd.a.b += [1]
|
||||||
|
assert_equal({a: {b: [0, 1]}}, dd)
|
||||||
END
|
END
|
||||||
CheckDefAndScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
@@ -1187,6 +1193,13 @@ def Test_assign_with_op_fails()
|
|||||||
s[1] ..= 'x'
|
s[1] ..= 'x'
|
||||||
END
|
END
|
||||||
CheckDefAndScriptFailure2(lines, 'E1141:', 'E689:', 2)
|
CheckDefAndScriptFailure2(lines, 'E1141:', 'E689:', 2)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var dd: dict<dict<list<any>>>
|
||||||
|
dd.a = {}
|
||||||
|
dd.a.b += [1]
|
||||||
|
END
|
||||||
|
CheckDefExecAndScriptFailure(lines, 'E716:', 3)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_assign_lambda()
|
def Test_assign_lambda()
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2722,
|
||||||
/**/
|
/**/
|
||||||
2721,
|
2721,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -6093,6 +6093,48 @@ compile_assign_index(
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For a LHS with an index, load the variable to be indexed.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
compile_load_lhs(
|
||||||
|
lhs_T *lhs,
|
||||||
|
char_u *var_start,
|
||||||
|
type_T *rhs_type,
|
||||||
|
cctx_T *cctx)
|
||||||
|
{
|
||||||
|
if (lhs->lhs_dest == dest_expr)
|
||||||
|
{
|
||||||
|
size_t varlen = lhs->lhs_varlen;
|
||||||
|
int c = var_start[varlen];
|
||||||
|
char_u *p = var_start;
|
||||||
|
garray_T *stack = &cctx->ctx_type_stack;
|
||||||
|
|
||||||
|
// Evaluate "ll[expr]" of "ll[expr][idx]"
|
||||||
|
var_start[varlen] = NUL;
|
||||||
|
if (compile_expr0(&p, cctx) == OK && p != var_start + varlen)
|
||||||
|
{
|
||||||
|
// this should not happen
|
||||||
|
emsg(_(e_missbrac));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
var_start[varlen] = c;
|
||||||
|
|
||||||
|
lhs->lhs_type = stack->ga_len == 0 ? &t_void
|
||||||
|
: ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
||||||
|
// now we can properly check the type
|
||||||
|
if (rhs_type != NULL && lhs->lhs_type->tt_member != NULL
|
||||||
|
&& rhs_type != &t_void
|
||||||
|
&& need_type(rhs_type, lhs->lhs_type->tt_member, -2, 0, cctx,
|
||||||
|
FALSE, FALSE) == FAIL)
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
generate_loadvar(cctx, lhs->lhs_dest, lhs->lhs_name,
|
||||||
|
lhs->lhs_lvar, lhs->lhs_type);
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Assignment to a list or dict member, or ":unlet" for the item, using the
|
* Assignment to a list or dict member, or ":unlet" for the item, using the
|
||||||
* information in "lhs".
|
* information in "lhs".
|
||||||
@@ -6106,9 +6148,7 @@ compile_assign_unlet(
|
|||||||
type_T *rhs_type,
|
type_T *rhs_type,
|
||||||
cctx_T *cctx)
|
cctx_T *cctx)
|
||||||
{
|
{
|
||||||
char_u *p;
|
|
||||||
vartype_T dest_type;
|
vartype_T dest_type;
|
||||||
size_t varlen = lhs->lhs_varlen;
|
|
||||||
garray_T *stack = &cctx->ctx_type_stack;
|
garray_T *stack = &cctx->ctx_type_stack;
|
||||||
int range = FALSE;
|
int range = FALSE;
|
||||||
|
|
||||||
@@ -6147,32 +6187,8 @@ compile_assign_unlet(
|
|||||||
// - index
|
// - index
|
||||||
// - for [a : b] second index
|
// - for [a : b] second index
|
||||||
// - variable
|
// - variable
|
||||||
if (lhs->lhs_dest == dest_expr)
|
if (compile_load_lhs(lhs, var_start, rhs_type, cctx) == FAIL)
|
||||||
{
|
|
||||||
int c = var_start[varlen];
|
|
||||||
|
|
||||||
// Evaluate "ll[expr]" of "ll[expr][idx]"
|
|
||||||
p = var_start;
|
|
||||||
var_start[varlen] = NUL;
|
|
||||||
if (compile_expr0(&p, cctx) == OK && p != var_start + varlen)
|
|
||||||
{
|
|
||||||
// this should not happen
|
|
||||||
emsg(_(e_missbrac));
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
|
||||||
var_start[varlen] = c;
|
|
||||||
|
|
||||||
lhs->lhs_type = stack->ga_len == 0 ? &t_void
|
|
||||||
: ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
|
||||||
// now we can properly check the type
|
|
||||||
if (lhs->lhs_type->tt_member != NULL && rhs_type != &t_void
|
|
||||||
&& need_type(rhs_type, lhs->lhs_type->tt_member, -2, 0, cctx,
|
|
||||||
FALSE, FALSE) == FAIL)
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
generate_loadvar(cctx, lhs->lhs_dest, lhs->lhs_name,
|
|
||||||
lhs->lhs_lvar, lhs->lhs_type);
|
|
||||||
|
|
||||||
if (dest_type == VAR_LIST || dest_type == VAR_DICT || dest_type == VAR_ANY)
|
if (dest_type == VAR_LIST || dest_type == VAR_DICT || dest_type == VAR_ANY)
|
||||||
{
|
{
|
||||||
@@ -6384,8 +6400,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
// for "+=", "*=", "..=" etc. first load the current value
|
// for "+=", "*=", "..=" etc. first load the current value
|
||||||
if (*op != '=')
|
if (*op != '=')
|
||||||
{
|
{
|
||||||
generate_loadvar(cctx, lhs.lhs_dest, lhs.lhs_name,
|
compile_load_lhs(&lhs, var_start, NULL, cctx);
|
||||||
lhs.lhs_lvar, lhs.lhs_type);
|
|
||||||
|
|
||||||
if (lhs.lhs_has_index)
|
if (lhs.lhs_has_index)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user