Fix up implict class/static methods

This commit is contained in:
K. Lange 2023-01-25 23:50:35 +09:00
parent 429c699c00
commit 8e80e04a33
2 changed files with 16 additions and 1 deletions

View File

@ -1622,8 +1622,8 @@ static void classBody(struct GlobalState * state, size_t blockWidth) {
static struct CompilerSpecialMethod { const char * name; int type; } compilerSpecialMethods[] = {
{"__init__", TYPE_INIT},
{"__class_getitem__", TYPE_CLASSMETHOD},
{"__init_subclass__", TYPE_CLASSMETHOD},
{"__new__", TYPE_STATIC},
{"__prepare__", TYPE_CLASSMETHOD},
{NULL,0}
};

View File

@ -82,6 +82,21 @@ KRK_StaticMethod(type,__new__) {
/* Now copy the values over */
krk_tableAddAll(&nspace->entries, &_class->methods);
KrkValue tmp;
if (krk_tableGet_fast(&_class->methods, S("__class_getitem__"), &tmp) && IS_CLOSURE(tmp)) {
AS_CLOSURE(tmp)->obj.flags |= KRK_OBJ_FLAGS_FUNCTION_IS_CLASS_METHOD;
}
if (krk_tableGet_fast(&_class->methods, S("__init_subclass__"), &tmp) && IS_CLOSURE(tmp)) {
AS_CLOSURE(tmp)->obj.flags |= KRK_OBJ_FLAGS_FUNCTION_IS_CLASS_METHOD;
}
if (krk_tableGet_fast(&_class->methods, S("__new__"), &tmp) && IS_CLOSURE(tmp)) {
AS_CLOSURE(tmp)->obj.flags |= KRK_OBJ_FLAGS_FUNCTION_IS_STATIC_METHOD;
}
krk_finalizeClass(_class);
_callSetName(_class);