py/runtime: Fix self arg passed to classmethod when accessed via super.

Thanks to @AJMansfield for the original test case.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2024-07-24 17:17:39 +10:00
parent 07bf3179f6
commit 233f5ce661
2 changed files with 35 additions and 0 deletions

View File

@@ -1153,6 +1153,10 @@ void mp_convert_member_lookup(mp_obj_t self, const mp_obj_type_t *type, mp_obj_t
// base type (which is what is passed in the `type` argument to this function).
if (self != MP_OBJ_NULL) {
type = mp_obj_get_type(self);
if (type == &mp_type_type) {
// `self` is already a type, so use `self` directly.
type = MP_OBJ_TO_PTR(self);
}
}
dest[0] = ((mp_obj_static_class_method_t *)MP_OBJ_TO_PTR(member))->fun;
dest[1] = MP_OBJ_FROM_PTR(type);