patch 9.1.1801: Vim9: misleading error when extending dictionary
Problem: Vim9: misleading error when extending dictionary
(lacygoill)
Solution: Give a proper error message when a Dict type is used with a
compound operator (Yegappan Lakshmanan)
fixes: #8072
closes: #18426
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
d35e5e4237
commit
ad43d2639d
@ -3438,6 +3438,27 @@ compile_assign_rhs(cctx_T *cctx, cac_T *cac)
|
||||
&cac->cac_skip_store);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns OK if "type" supports compound operator "op_arg" (e.g. +=, -=, %=,
|
||||
* etc.). Compound operators are not supported with a tuple and a dict.
|
||||
* Returns FAIL if compound operator is not supported.
|
||||
*/
|
||||
static int
|
||||
check_type_supports_compound_op(type_T *type, char_u op_arg)
|
||||
{
|
||||
if (type->tt_type == VAR_TUPLE || type->tt_type == VAR_DICT)
|
||||
{
|
||||
char_u op[2];
|
||||
|
||||
op[0] = op_arg;
|
||||
op[1] = NUL;
|
||||
semsg(_(e_wrong_variable_type_for_str_equal), op);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compile a compound op assignment statement (+=, -=, *=, %=, etc.)
|
||||
*/
|
||||
@ -3448,16 +3469,10 @@ compile_assign_compound_op(cctx_T *cctx, cac_T *cac)
|
||||
type_T *expected;
|
||||
type_T *stacktype = NULL;
|
||||
|
||||
if (cac->cac_lhs.lhs_type->tt_type == VAR_TUPLE)
|
||||
{
|
||||
// compound operators are not supported with a tuple
|
||||
char_u op[2];
|
||||
|
||||
op[0] = *cac->cac_op;
|
||||
op[1] = NUL;
|
||||
semsg(_(e_wrong_variable_type_for_str_equal), op);
|
||||
if (cac->cac_lhs.lhs_type->tt_type == VAR_TUPLE
|
||||
&& check_type_supports_compound_op(cac->cac_lhs.lhs_type,
|
||||
*cac->cac_op) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (*cac->cac_op == '.')
|
||||
{
|
||||
@ -3474,6 +3489,10 @@ compile_assign_compound_op(cctx_T *cctx, cac_T *cac)
|
||||
{
|
||||
expected = lhs->lhs_member_type;
|
||||
stacktype = get_type_on_stack(cctx, 0);
|
||||
|
||||
if (check_type_supports_compound_op(expected, *cac->cac_op) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
if (
|
||||
// If variable is float operation with number is OK.
|
||||
!(expected == &t_float && (stacktype == &t_number
|
||||
|
||||
Reference in New Issue
Block a user