Mercurial > vim
diff src/vim9execute.c @ 33297:6340c608ca54 v9.0.1914
patch 9.0.1914: Vim9: few issues when accessing object members
Commit: https://github.com/vim/vim/commit/1db151436541a3e64cdd5e3d9eb3ace1ce1e1ad0
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Tue Sep 19 20:34:05 2023 +0200
patch 9.0.1914: Vim9: few issues when accessing object members
Problem: Vim9: few issues when accessing object members
Solution: When calling an object method, check for null object.
Accessing a Dict object member doesn't work.
closes: #13119
closes: #13123
closes: #13124
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 19 Sep 2023 20:45:06 +0200 |
parents | aba1fa2b7d1e |
children | 4e531adb3fac |
line wrap: on
line diff
--- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -535,6 +535,15 @@ call_dfunc( // If this is an object method, the object is just before the arguments. typval_T *obj = STACK_TV_BOT(0) - argcount - vararg_count - 1; + if (obj->v_type == VAR_OBJECT && obj->vval.v_object == NULL + && !IS_CONSTRUCTOR_METHOD(ufunc)) + { + // If this is not the constructor method, then a valid object is + // needed. + emsg(_(e_using_null_object)); + return FAIL; + } + // Check the argument types. if (check_ufunc_arg_types(ufunc, argcount, vararg_count, ectx) == FAIL) return FAIL; @@ -599,7 +608,7 @@ call_dfunc( // For an object method move the object from just before the arguments to // the first local variable. - if (ufunc->uf_flags & FC_OBJECT) + if (IS_OBJECT_METHOD(ufunc)) { *STACK_TV_VAR(0) = *obj; obj->v_type = VAR_UNKNOWN; @@ -1148,7 +1157,7 @@ func_return(ectx_T *ectx) // Clear the arguments. If this was an object method also clear the // object, it is just before the arguments. int top = ectx->ec_frame_idx - argcount; - if (dfunc->df_ufunc->uf_flags & FC_OBJECT) + if (IS_OBJECT_METHOD(dfunc->df_ufunc)) --top; for (idx = top; idx < ectx->ec_frame_idx; ++idx) clear_tv(STACK_TV(idx));