@@ -3162,34 +3162,53 @@ object_required_error(typval_T *tv)
31623162}
31633163
31643164/*
3165- * Accessing the member of an object stored in a variable of type "any".
3165+ * Accessing the variable or method of an object or a class stored in a
3166+ * variable of type "any".
31663167 * Returns OK if the member variable is present.
31673168 * Returns FAIL if the variable is not found.
31683169 */
31693170 static int
3170- any_var_get_obj_member (class_T * current_class , isn_T * iptr , typval_T * tv )
3171+ var_any_get_oc_member (class_T * current_class , isn_T * iptr , typval_T * tv )
31713172{
3172- object_T * obj = tv -> vval .v_object ;
3173+ int is_object = tv -> v_type == VAR_OBJECT ;
3174+ class_T * tv_cl ;
3175+ object_T * obj = NULL ;
31733176 typval_T mtv ;
31743177
3175- if (obj == NULL )
3178+ if (is_object )
31763179 {
3177- SOURCING_LNUM = iptr -> isn_lnum ;
3178- emsg (_ (e_using_null_object ));
3179- return FAIL ;
3180+ obj = tv -> vval .v_object ;
3181+ if (obj == NULL )
3182+ {
3183+ SOURCING_LNUM = iptr -> isn_lnum ;
3184+ emsg (_ (e_using_null_object ));
3185+ return FAIL ;
3186+ }
3187+ tv_cl = obj -> obj_class ;
3188+ }
3189+ else
3190+ {
3191+ tv_cl = tv -> vval .v_class ;
3192+ if (tv_cl == NULL )
3193+ {
3194+ SOURCING_LNUM = iptr -> isn_lnum ;
3195+ emsg (_ (e_using_null_class ));
3196+ return FAIL ;
3197+ }
31803198 }
31813199
3182- // get_member_tv() needs the object information in the typval argument.
3183- // So set the object information.
3200+ // get_member_tv() needs the class/ object information in the typval
3201+ // argument. So set the object information.
31843202 copy_tv (tv , & mtv );
31853203
3186- // 'name' can either be a object variable or a object method
3204+ // 'name' can either be an instance or class variable or method
31873205 int namelen = (int )STRLEN (iptr -> isn_arg .string );
31883206 int save_did_emsg = did_emsg ;
31893207
3190- if (get_member_tv (obj -> obj_class , TRUE , iptr -> isn_arg .string , namelen ,
3208+ if (get_member_tv (tv_cl , is_object , iptr -> isn_arg .string , namelen ,
31913209 current_class , & mtv ) == OK )
31923210 {
3211+ // instance or class variable
31933212 copy_tv (& mtv , tv );
31943213 clear_tv (& mtv );
31953214 return OK ;
@@ -3198,31 +3217,36 @@ any_var_get_obj_member(class_T *current_class, isn_T *iptr, typval_T *tv)
31983217 if (did_emsg != save_did_emsg )
31993218 return FAIL ;
32003219
3201- // could be a member function
3202- ufunc_T * obj_method ;
3203- int obj_method_idx ;
3220+ // could be a class or instance method
3221+ ufunc_T * oc_method ;
3222+ int oc_method_idx ;
32043223
3205- obj_method = method_lookup (obj -> obj_class , VAR_OBJECT ,
3206- iptr -> isn_arg .string , namelen ,
3207- & obj_method_idx );
3208- if (obj_method == NULL )
3224+ oc_method = method_lookup (tv_cl , tv -> v_type , iptr -> isn_arg .string ,
3225+ namelen , & oc_method_idx );
3226+ if (oc_method == NULL )
32093227 {
3228+ char * msg ;
3229+
32103230 SOURCING_LNUM = iptr -> isn_lnum ;
3211- semsg (_ (e_variable_not_found_on_object_str_str ), iptr -> isn_arg .string ,
3212- obj -> obj_class -> class_name );
3231+ if (is_object )
3232+ msg = e_variable_not_found_on_object_str_str ;
3233+ else
3234+ msg = e_class_variable_str_not_found_in_class_str ;
3235+ semsg (_ (msg ), iptr -> isn_arg .string , tv_cl -> class_name );
32133236 return FAIL ;
32143237 }
32153238
32163239 // Protected methods are not accessible outside the class
3217- if (* obj_method -> uf_name == '_'
3218- && !class_instance_of (current_class , obj -> obj_class ))
3240+ if (* oc_method -> uf_name == '_'
3241+ && !class_instance_of (current_class , tv_cl ))
32193242 {
3220- semsg (_ (e_cannot_access_protected_method_str ), obj_method -> uf_name );
3243+ semsg (_ (e_cannot_access_protected_method_str ), oc_method -> uf_name );
32213244 return FAIL ;
32223245 }
32233246
3224- // Create a partial for the member function
3225- if (obj_method_to_partial_tv (obj , obj_method , tv ) == FAIL )
3247+ // Create a partial for the instance or class method
3248+ if (obj_method_to_partial_tv (is_object ? obj : NULL , oc_method , tv )
3249+ == FAIL )
32263250 return FAIL ;
32273251
32283252 return OK ;
@@ -5671,15 +5695,16 @@ exec_instructions(ectx_T *ectx)
56715695
56725696 tv = STACK_TV_BOT (-1 );
56735697
5674- if (tv -> v_type == VAR_OBJECT )
5698+ if (tv -> v_type == VAR_OBJECT
5699+ || tv -> v_type == VAR_CLASS )
56755700 {
56765701 if (dict_stack_save (tv ) == FAIL )
56775702 goto on_fatal_error ;
56785703
56795704 ufunc_T * ufunc = (((dfunc_T * )def_functions .ga_data )
56805705 + ectx -> ec_dfunc_idx )-> df_ufunc ;
5681- // Class object (not a Dict)
5682- if (any_var_get_obj_member (ufunc -> uf_class , iptr , tv ) == FAIL )
5706+ // Class or an object (not a Dict)
5707+ if (var_any_get_oc_member (ufunc -> uf_class , iptr , tv ) == FAIL )
56835708 goto on_error ;
56845709 }
56855710 else
0 commit comments