diff options
author | Bram Moolenaar <Bram@vim.org> | 2023-02-08 20:55:27 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-02-08 20:55:27 +0000 |
commit | 313e4724c3b4f6d7454b45b89da08f83a2a0c77e (patch) | |
tree | 2ba9f67c93d6502c31e2896d546cbfd45994e03c /src/vim9execute.c | |
parent | 6642982beaf4f1f5164f0315a1b3e3c275156089 (diff) | |
download | vim-git-313e4724c3b4f6d7454b45b89da08f83a2a0c77e.tar.gz |
patch 9.0.1292: :defer may call the wrong method for an objectv9.0.1292
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)
Diffstat (limited to 'src/vim9execute.c')
-rw-r--r-- | src/vim9execute.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/vim9execute.c b/src/vim9execute.c index 3498e547e..605cfb25c 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -4291,7 +4291,24 @@ exec_instructions(ectx_T *ectx) vim_free(pt); goto theend; } - if (extra == NULL || extra->fre_func_name == NULL) + if (extra != NULL && extra->fre_class != NULL) + { + tv = STACK_TV_BOT(-1); + if (tv->v_type != VAR_OBJECT) + { + object_required_error(tv); + vim_free(pt); + goto on_error; + } + object_T *obj = tv->vval.v_object; + class_T *cl = obj->obj_class; + + // convert the interface index to the object index + int idx = object_index_from_itf_index(extra->fre_class, + TRUE, extra->fre_method_idx, cl); + ufunc = cl->class_obj_methods[idx]; + } + else if (extra == NULL || extra->fre_func_name == NULL) { dfunc_T *pt_dfunc = ((dfunc_T *)def_functions.ga_data) + funcref->fr_dfunc_idx; @@ -4299,7 +4316,9 @@ exec_instructions(ectx_T *ectx) ufunc = pt_dfunc->df_ufunc; } else + { ufunc = find_func(extra->fre_func_name, FALSE); + } if (ufunc == NULL) { SOURCING_LNUM = iptr->isn_lnum; @@ -6727,8 +6746,16 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc) } else name = extra->fre_func_name; - if (extra == NULL || extra->fre_loopvar_info.lvi_depth == 0) + if (extra != NULL && extra->fre_class != NULL) + { + smsg("%s%4d FUNCREF %s.%s", pfx, current, + extra->fre_class->class_name, name); + } + else if (extra == NULL + || extra->fre_loopvar_info.lvi_depth == 0) + { smsg("%s%4d FUNCREF %s", pfx, current, name); + } else { char_u *info = printable_loopvarinfo( |