1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Allow bind to 'this' functions without target

This commit is contained in:
Brian Fiete 2020-09-10 11:26:34 -07:00
parent a852bdb8cc
commit 6b6be04a22

View file

@ -5447,9 +5447,23 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
moduleMethodInstance.mFunc = mModule->mBfIRBuilder->CreateIntToPtr(target.mValue, funcPtrType);
}
else if (!methodDef->mIsStatic)
{
if (!target)
{
if ((!target) && (prevBindResult.mPrevVal != NULL))
{
auto bindResult = prevBindResult.mPrevVal;
if (bindResult->mBindType != NULL)
{
auto delegateInfo = bindResult->mBindType->GetDelegateInfo();
if ((delegateInfo != NULL) && (delegateInfo->mFunctionThisType != NULL))
{
// Allow binding a function to a 'this' type even if no target is specified
target = mModule->GetDefaultTypedValue(delegateInfo->mFunctionThisType, false, BfDefaultValueKind_Addr);
}
}
}
if (!target)
{
FinishDeferredEvals(argValues);
auto error = mModule->Fail(StrFormat("An instance reference is required to %s the non-static method '%s'",
(prevBindResult.mPrevVal != NULL) ? "bind" : "invoke",