Mercurial > vim
diff src/vim9expr.c @ 31920:f1a5e67e9a1b v9.0.1292
patch 9.0.1292: :defer may call the wrong method for an object
Commit: https://github.com/vim/vim/commit/313e4724c3b4f6d7454b45b89da08f83a2a0c77e
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 8 20:55:27 2023 +0000
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 08 Feb 2023 22:00:06 +0100 |
parents | ffa11e2757e7 |
children | 9113d903a2c6 |
line wrap: on
line diff
--- a/src/vim9expr.c +++ b/src/vim9expr.c @@ -383,7 +383,12 @@ compile_class_object_index(cctx_T *cctx, // 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 @@ compile_lambda(char_u **arg, cctx_T *cct // 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);