diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2023-09-01 22:05:45 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-09-01 22:05:45 +0200 |
commit | 3775f777a6add2a8d5060b40414e9c53062c8cd9 (patch) | |
tree | c6db91ae9aa6226189470956b435feadba9b56ad /src/vim9execute.c | |
parent | b147d314897b7a82081644edf779e22138d44f2c (diff) |
patch 9.0.1838: Vim9: Cannot modify class member vars from def functionv9.0.1838
Problem: Vim9: Cannot modify class member vars from def function
Solution: Add support for modifying class member variables from a def
function
closes: #12995
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/vim9execute.c')
-rw-r--r-- | src/vim9execute.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/vim9execute.c b/src/vim9execute.c index b26934dc47..2fbce780f7 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -2144,7 +2144,7 @@ execute_storeindex(isn_T *iptr, ectx_T *ectx) // Stack contains: // -3 value to be stored // -2 index - // -1 dict, list, blob or object + // -1 dict, list, blob, object or class tv = STACK_TV_BOT(-3); SOURCING_LNUM = iptr->isn_lnum; @@ -2306,14 +2306,25 @@ execute_storeindex(isn_T *iptr, ectx_T *ectx) } else if (dest_type == VAR_CLASS || dest_type == VAR_OBJECT) { - object_T *obj = tv_dest->vval.v_object; - typval_T *otv = (typval_T *)(obj + 1); - - class_T *itf = iptr->isn_arg.storeindex.si_class; - if (itf != NULL) - // convert interface member index to class member index - lidx = object_index_from_itf_index(itf, FALSE, - lidx, obj->obj_class); + typval_T *otv; + + if (dest_type == VAR_OBJECT) + { + object_T *obj = tv_dest->vval.v_object; + + otv = (typval_T *)(obj + 1); + class_T *itf = iptr->isn_arg.storeindex.si_class; + if (itf != NULL) + // convert interface member index to class member index + lidx = object_index_from_itf_index(itf, FALSE, + lidx, obj->obj_class); + } + else + { + // VAR_CLASS + class_T *class = tv_dest->vval.v_class; + otv = class->class_members_tv; + } clear_tv(&otv[lidx]); otv[lidx] = *tv; |