patch 9.0.1178: a child class cannot override functions from a base class
Problem: A child class cannot override functions from a base class.
Solution: Allow overriding and implement "super".
diff --git a/src/vim9compile.c b/src/vim9compile.c
index d8e4ae6..9fe8507 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -43,16 +43,31 @@
if (len == 0)
return FAIL;
- if (len == 4 && STRNCMP(name, "this", 4) == 0
+ if (((len == 4 && STRNCMP(name, "this", 4) == 0)
+ || (len == 5 && STRNCMP(name, "super", 5) == 0))
&& cctx->ctx_ufunc != NULL
&& (cctx->ctx_ufunc->uf_flags & (FC_OBJECT|FC_NEW)))
{
+ int is_super = *name == 's';
if (lvar != NULL)
{
CLEAR_POINTER(lvar);
- lvar->lv_name = (char_u *)"this";
+ lvar->lv_name = (char_u *)(is_super ? "super" : "this");
if (cctx->ctx_ufunc->uf_class != NULL)
+ {
lvar->lv_type = &cctx->ctx_ufunc->uf_class->class_object_type;
+ if (is_super)
+ {
+ type_T *type = get_type_ptr(cctx->ctx_type_list);
+
+ if (type != NULL)
+ {
+ *type = *lvar->lv_type;
+ lvar->lv_type = type;
+ type->tt_flags |= TTFLAG_SUPER;
+ }
+ }
+ }
}
return OK;
}