diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2024-02-06 11:03:36 +0100 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2024-02-06 11:03:36 +0100 |
commit | 1af35631f85d2fcdc83c5d457af8273697f5146a (patch) | |
tree | 10d2dc574d3ff18984f9d00c6fe339260a6d4fc6 /src/evalvars.c | |
parent | ebfd856cfdf6ea0b16c8d115000961c998ce97da (diff) |
patch 9.1.0080: unexpected error for modifying final list using +=v9.1.0080
Problem: unexpected error for modifying final list using += operator
(Ernie Rael)
Solution: Allow List value modification of a final variable using +=
operator
(Yegappan Lakshmanan)
fixes: #13745
fixes: #13959
closes: #13962
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/evalvars.c')
-rw-r--r-- | src/evalvars.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index cbcf2a707e..0a84afdaaf 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -3977,7 +3977,14 @@ set_var_const( if (check_typval_is_value(&di->di_tv) == FAIL) goto failed; - if (var_in_vim9script && (flags & ASSIGN_FOR_LOOP) == 0) + // List and Blob types can be modified in-place using the "+=" + // compound operator. For other types, this is not allowed. + int type_inplace_modifiable = + (di->di_tv.v_type == VAR_LIST || di->di_tv.v_type == VAR_BLOB); + + if (var_in_vim9script && (flags & ASSIGN_FOR_LOOP) == 0 + && ((flags & ASSIGN_COMPOUND_OP) == 0 + || !type_inplace_modifiable)) { where_T where = WHERE_INIT; svar_T *sv = find_typval_in_script(&di->di_tv, sid, TRUE); @@ -3998,7 +4005,11 @@ set_var_const( } } - if ((flags & ASSIGN_FOR_LOOP) == 0 + // Modifying a final variable with a List value using the "+=" + // operator is allowed. For other types, it is not allowed. + if (((flags & ASSIGN_FOR_LOOP) == 0 + && ((flags & ASSIGN_COMPOUND_OP) == 0 + || !type_inplace_modifiable)) ? var_check_permission(di, name) == FAIL : var_check_ro(di->di_flags, name, FALSE)) goto failed; |