patch 9.0.1292: :defer may call the wrong method for an object
Problem: :defer may call the wrong method for an object. (Ernie Rael)
Solution: When en object is from a class that extends or implements, figure
out the method to call at runtime. (closes #11910)
diff --git a/src/vim9expr.c b/src/vim9expr.c
index c65fc79..88d9ec1 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -383,7 +383,12 @@
// uf_name[] only being 4 characters.
char_u *ufname = (char_u *)fp->uf_name;
if (STRNCMP(name, ufname, len) == 0 && ufname[len] == NUL)
- return generate_FUNCREF(cctx, fp, NULL);
+ {
+ if (type->tt_type == VAR_OBJECT
+ && (cl->class_flags & (CLASS_INTERFACE | CLASS_EXTENDED)))
+ return generate_FUNCREF(cctx, fp, cl, i, NULL);
+ return generate_FUNCREF(cctx, fp, NULL, 0, NULL);
+ }
}
semsg(_(e_member_not_found_on_object_str_str), cl->class_name, name);
@@ -1308,7 +1313,7 @@
// The function reference count will be 1. When the ISN_FUNCREF
// instruction is deleted the reference count is decremented and the
// function is freed.
- return generate_FUNCREF(cctx, ufunc, NULL);
+ return generate_FUNCREF(cctx, ufunc, NULL, 0, NULL);
}
func_ptr_unref(ufunc);