patch 9.1.1116: Vim9: super not supported in lambda expressions
Problem: Vim9: super not supported in lambda expressions
(Aliaksei Budavei)
Solution: Support using the super keyword in a closure in an instance
method (Yegappan Lakshmanan)
fixes: #16586
closes: #16647
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/vim9expr.c b/src/vim9expr.c
index fe2be41..67722d1 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -291,7 +291,7 @@
}
class_T *cl = type->tt_class;
- int is_super = type->tt_flags & TTFLAG_SUPER;
+ int is_super = ((type->tt_flags & TTFLAG_SUPER) == TTFLAG_SUPER);
if (type == &t_super)
{
if (cctx->ctx_ufunc == NULL || cctx->ctx_ufunc->uf_class == NULL)
@@ -694,6 +694,26 @@
}
/*
+ * Returns TRUE if compiling a class method.
+ */
+ static int
+compiling_a_class_method(cctx_T *cctx)
+{
+ // For an object method, the FC_OBJECT flag will be set.
+ // For a constructor method, the FC_NEW flag will be set.
+ // Excluding these methods, the others are class methods.
+ // When compiling a closure function inside an object method,
+ // cctx->ctx_outer->ctx_func will point to the object method.
+ return cctx->ctx_ufunc != NULL
+ && (cctx->ctx_ufunc->uf_flags & (FC_OBJECT|FC_NEW)) == 0
+ && (cctx->ctx_outer == NULL
+ || cctx->ctx_outer->ctx_ufunc == NULL
+ || cctx->ctx_outer->ctx_ufunc->uf_class == NULL
+ || (cctx->ctx_outer->ctx_ufunc->uf_flags
+ & (FC_OBJECT|FC_NEW)) == 0);
+}
+
+/*
* Compile a variable name into a load instruction.
* "end" points to just after the name.
* "is_expr" is TRUE when evaluating an expression, might be a funcref.
@@ -807,9 +827,7 @@
if (name == NULL)
return FAIL;
- if (STRCMP(name, "super") == 0
- && cctx->ctx_ufunc != NULL
- && (cctx->ctx_ufunc->uf_flags & (FC_OBJECT|FC_NEW)) == 0)
+ if (STRCMP(name, "super") == 0 && compiling_a_class_method(cctx))
{
// super.SomeFunc() in a class function: push &t_super type, this
// is recognized in compile_subscript().