From a8610ed7116582be851e765548f650b3df74d181 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 26 Dec 2020 08:27:46 -0800 Subject: [PATCH] Added stricter 'this' type check for generic function binding --- IDEHelper/Compiler/BfExprEvaluator.cpp | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 6863b4ce..1c42069c 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -10751,12 +10751,29 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr) result = mModule->mBfIRBuilder->CreatePtrToInt(funcValue, BfTypeCode_IntPtr); } } - else if ((bindResult.mOrigTarget) && (bindResult.mOrigTarget.mType->IsGenericParam()) && (bindResult.mMethodInstance->GetOwner()->IsInterface())) - { - result = mModule->mBfIRBuilder->GetFakeVal(); - } - else - { + else + { + if ((bindResult.mOrigTarget) && (bindResult.mOrigTarget.mType->IsGenericParam()) && (bindResult.mMethodInstance->GetOwner()->IsInterface())) + { + bool matching = true; + if (methodInstance->HasExplicitThis()) + { + auto thisType = methodInstance->GetParamType(0); + + if (thisType->IsPointer()) + thisType = thisType->GetUnderlyingType(); + if (thisType->IsRef()) + thisType = thisType->GetUnderlyingType(); + + matching = thisType == bindResult.mOrigTarget.mType; + } + + if (matching) + { + mResult = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), mExpectingType); + return; + } + } result = mModule->CastToFunction(delegateBindExpr->mTarget, bindResult.mOrigTarget, bindResult.mMethodInstance, mExpectingType); } if (result)