From 9cea226619e736e8c3f0efc1210d2b9e56edd2cc Mon Sep 17 00:00:00 2001 From: jacopodl Date: Fri, 2 Aug 2024 15:35:22 +0200 Subject: [PATCH] fix: correct behavior when using method object as variable value across different structures Resolved issues that occurred when assigning a method from one struct as a variable value in a different struct, ensuring proper method binding and execution. --- argon/vm/datatype/arobject.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/argon/vm/datatype/arobject.cpp b/argon/vm/datatype/arobject.cpp index 76bfc96c..57c18d53 100644 --- a/argon/vm/datatype/arobject.cpp +++ b/argon/vm/datatype/arobject.cpp @@ -307,7 +307,13 @@ ArObject *argon::vm::datatype::AttributeLoadMethod(const ArObject *object, ArObj if ((aload = AttributeLoad(object, key, false)) == nullptr) return nullptr; - if (AR_TYPEOF(aload, type_function_) && ((Function *) aload)->IsMethod()) + const auto *func = (Function *) aload; + const auto *base = (TypeInfo *) object; + + if(AR_GET_TYPE(base) != type_type_) + base = AR_GET_TYPE(base); + + if (AR_TYPEOF(func, type_function_) && func->IsMethod() && TraitIsImplemented(base, func->base)) *is_method = true; return aload;