patch 9.0.1041: cannot define a method in a class
Problem: Cannot define a method in a class.
Solution: Implement defining an object method. Make calling an object
method work.
diff --git a/src/vim9instr.c b/src/vim9instr.c
index cd5597d..88bd2ca 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -132,6 +132,23 @@
}
/*
+ * Generate ISN_OBJ_MEMBER - access object member by indes.
+ */
+ int
+generate_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type)
+{
+ RETURN_OK_IF_SKIP(cctx);
+
+ // drop the object type
+ isn_T *isn = generate_instr_drop(cctx, ISN_OBJ_MEMBER, 1);
+ if (isn == NULL)
+ return FAIL;
+
+ isn->isn_arg.number = idx;
+ return push_type_stack2(cctx, type, &t_any);
+}
+
+/*
* If type at "offset" isn't already VAR_STRING then generate ISN_2STRING.
* But only for simple types.
* When "tolerant" is TRUE convert most types to string, e.g. a List.
@@ -2460,6 +2477,7 @@
case ISN_NEWDICT:
case ISN_NEWLIST:
case ISN_NEWPARTIAL:
+ case ISN_OBJ_MEMBER:
case ISN_OPANY:
case ISN_OPFLOAT:
case ISN_OPNR: