From 6b6be04a224e42b74eb50b9022d50bde82c1654c Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 10 Sep 2020 11:26:34 -0700 Subject: [PATCH] Allow bind to 'this' functions without target --- IDEHelper/Compiler/BfExprEvaluator.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 9e1e2ba6..75afc29c 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -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",