Hello. I've been trying to add some qol annotations to our codebase and came across a problem in the Reflection I just haven't been able to figure out how to get around:
MyClass::myFunction
returns a different type to
MyClass::class.functions.find{myFunction}
- I only have access to the reflected classes and the code that's going to be calling these functions works perfect when I use
MyClass::myFunction
, however when i get hold of the function via
MyClass::class.functions
it expects more arguments than the actual function. Any way I can get to the same reflected function as
MyClass::myFunction
from
MyClass::class.functions
? Thanks
ndv
02/27/2018, 5:59 PM
I have now tried to replicate the problem in an empty project, and while there's still a difference, its a different case to what I'm getting in my main codebase. For some reason the class itself is part of the function parameters during reflection, though not during definition.
ndv
02/27/2018, 6:11 PM
In case anyone comes across this.
MyClass, in this instance, is defined as an object, i.e.
MyClass::myFunction
results in a boundInstanceMethod whereas
MyClass::class::functions
delivers an InstanceMethod - this is where the difference came in. I'll have to find some workaround for this or alter the codebase
r
Rafael Chaves
02/27/2018, 7:58 PM
@ndv There was a recent thread on the #C0AVAB92L channel somewhat related to this. You have to pass the target object as a parameter when invoking the unbound function.
Rafael Chaves
02/27/2018, 8:02 PM
You either have to insert the target object as a first element of the arg array in a call to call(), or as an entry in the arg map in a call to callBy()