patch 9.0.0840: cannot change a slice of a const list
Problem: Cannot change a slice of a const list. (Takumi KAGIYAMA)
Solution: Remove the const flag from the slice type. (closes #11490)
diff --git a/src/vim9expr.c b/src/vim9expr.c
index 7a32974..7a089e9 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -185,6 +185,18 @@
// a copy is made so the member type is no longer declared
if (typep->type_decl->tt_type == VAR_LIST)
typep->type_decl = &t_list_any;
+
+ // a copy is made, the composite is no longer "const"
+ if (typep->type_curr->tt_flags & TTFLAG_CONST)
+ {
+ type_T *type = copy_type(typep->type_curr, cctx->ctx_type_list);
+
+ if (type != typep->type_curr) // did get a copy
+ {
+ type->tt_flags &= ~(TTFLAG_CONST | TTFLAG_STATIC);
+ typep->type_curr = type;
+ }
+ }
}
else
{