1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Allow function binding to generic interface constraint method

This commit is contained in:
Brian Fiete 2020-12-26 08:19:30 -08:00
parent 5808bd555c
commit 6029315ff6
2 changed files with 9 additions and 2 deletions

View file

@ -8397,6 +8397,9 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
needsMut = false; needsMut = false;
} }
if ((mFunctionBindResult != NULL) && (mFunctionBindResult->mSkipMutCheck))
needsMut = false;
if (needsMut) if (needsMut)
{ {
String err = StrFormat("call mutating method '%s' on", mModule->MethodToString(moduleMethodInstance.mMethodInstance).c_str()); String err = StrFormat("call mutating method '%s' on", mModule->MethodToString(moduleMethodInstance.mMethodInstance).c_str());
@ -10748,8 +10751,12 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr)
result = mModule->mBfIRBuilder->CreatePtrToInt(funcValue, BfTypeCode_IntPtr); result = mModule->mBfIRBuilder->CreatePtrToInt(funcValue, BfTypeCode_IntPtr);
} }
} }
else else if ((bindResult.mOrigTarget) && (bindResult.mOrigTarget.mType->IsGenericParam()) && (bindResult.mMethodInstance->GetOwner()->IsInterface()))
{ {
result = mModule->mBfIRBuilder->GetFakeVal();
}
else
{
result = mModule->CastToFunction(delegateBindExpr->mTarget, bindResult.mOrigTarget, bindResult.mMethodInstance, mExpectingType); result = mModule->CastToFunction(delegateBindExpr->mTarget, bindResult.mOrigTarget, bindResult.mMethodInstance, mExpectingType);
} }
if (result) if (result)

View file

@ -3813,7 +3813,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
bool isMutating = true; bool isMutating = true;
int paramRefOfs = 0; int paramRefOfs = 0;
if (!rhsDelegateType->mParams.IsEmpty()) if ((!rhsDelegateType->mParams.IsEmpty()) && (lhs->IsFunction()))
{ {
auto param0 = rhsDelegateType->mParams[0]; auto param0 = rhsDelegateType->mParams[0];
if ((param0->mNameNode != NULL) && (param0->mNameNode->Equals("this"))) if ((param0->mNameNode != NULL) && (param0->mNameNode->Equals("this")))