From 8e80e04a333373f844a5448852e97a56f55bef68 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Wed, 25 Jan 2023 23:50:35 +0900 Subject: [PATCH] Fix up implict class/static methods --- src/compiler.c | 2 +- src/obj_base.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/compiler.c b/src/compiler.c index 196a6ca..45ce602 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -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} }; diff --git a/src/obj_base.c b/src/obj_base.c index a6dedf7..ad365d3 100644 --- a/src/obj_base.c +++ b/src/obj_base.c @@ -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);