patch 9.0.1045: in a class object members cannot be initialized
Problem: In a class object members cannot be initialized.
Solution: Support initializing object members. Make "dissassemble" work on
an object method.
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 96983bb..6a6ec41 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -3009,7 +3009,7 @@
iptr = &ectx->ec_instr[ectx->ec_iidx++];
switch (iptr->isn_type)
{
- // Constructor, new() method.
+ // Constructor, first instruction in a new() method.
case ISN_CONSTRUCT:
// "this" is always the local variable at index zero
tv = STACK_TV_VAR(0);
@@ -5114,7 +5114,7 @@
}
break;
- case ISN_OBJ_MEMBER:
+ case ISN_GET_OBJ_MEMBER:
{
tv = STACK_TV_BOT(-1);
if (tv->v_type != VAR_OBJECT)
@@ -5143,6 +5143,18 @@
}
break;
+ case ISN_STORE_THIS:
+ {
+ int idx = iptr->isn_arg.number;
+ object_T *obj = STACK_TV_VAR(0)->vval.v_object;
+ // the members are located right after the object struct
+ typval_T *mtv = ((typval_T *)(obj + 1)) + idx;
+ clear_tv(mtv);
+ *mtv = *STACK_TV_BOT(-1);
+ --ectx->ec_stack.ga_len;
+ }
+ break;
+
case ISN_CLEARDICT:
dict_stack_drop();
break;
@@ -6805,7 +6817,9 @@
case ISN_MEMBER: smsg("%s%4d MEMBER", pfx, current); break;
case ISN_STRINGMEMBER: smsg("%s%4d MEMBER %s", pfx, current,
iptr->isn_arg.string); break;
- case ISN_OBJ_MEMBER: smsg("%s%4d OBJ_MEMBER %d", pfx, current,
+ case ISN_GET_OBJ_MEMBER: smsg("%s%4d OBJ_MEMBER %d", pfx, current,
+ (int)iptr->isn_arg.number); break;
+ case ISN_STORE_THIS: smsg("%s%4d STORE_THIS %d", pfx, current,
(int)iptr->isn_arg.number); break;
case ISN_CLEARDICT: smsg("%s%4d CLEARDICT", pfx, current); break;
case ISN_USEDICT: smsg("%s%4d USEDICT", pfx, current); break;