diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2023-09-19 20:34:05 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-09-19 20:36:02 +0200 |
commit | 1db151436541a3e64cdd5e3d9eb3ace1ce1e1ad0 (patch) | |
tree | 04a55e05000bc0b00366825c1088d3dd8481dbfe /src/vim9execute.c | |
parent | 2ce070c27acd12ccc614afa4cecf4970a645a4af (diff) |
patch 9.0.1914: Vim9: few issues when accessing object membersv9.0.1914
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>
Diffstat (limited to 'src/vim9execute.c')
-rw-r--r-- | src/vim9execute.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/vim9execute.c b/src/vim9execute.c index 7c61ff418e..23dee1cfca 100644 --- 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)); |