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

Diallow mut mismatch on function bind

This commit is contained in:
Brian Fiete 2021-12-15 10:48:42 -05:00
parent ba9d99fa76
commit 6a95cbb3b8
4 changed files with 26 additions and 20 deletions

View file

@ -11141,7 +11141,6 @@ bool BfExprEvaluator::IsExactMethodMatch(BfMethodInstance* methodA, BfMethodInst
{
if (methodA->mReturnType != methodB->mReturnType)
return false;
int implicitParamCountA = methodA->GetImplicitParamCount();
if (methodA->HasExplicitThis())
implicitParamCountA++;
@ -11703,7 +11702,11 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr)
}
else
{
if (!IsExactMethodMatch(methodInstance, bindMethodInstance, true))
bool isExactMethodMatch = IsExactMethodMatch(methodInstance, bindMethodInstance, true);
if ((mExpectingType != NULL) && (mExpectingType->IsFunction()) && (methodInstance->mMethodDef->mIsMutating != bindMethodInstance->mMethodDef->mIsMutating))
isExactMethodMatch = false;
if (!isExactMethodMatch)
{
if (bindResult.mCheckedMultipleMethods)
{
@ -11712,7 +11715,7 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr)
}
else
{
mModule->Fail(StrFormat("Method '%s' does not match %s '%s'", mModule->MethodToString(bindMethodInstance).c_str(), bindTypeName,
mModule->Fail(StrFormat("Method '%s' does not match %s '%s'", mModule->MethodToString(bindMethodInstance, (BfMethodNameFlags)(BfMethodNameFlag_IncludeReturnType | BfMethodNameFlag_IncludeMut)).c_str(), bindTypeName,
mModule->TypeToString(delegateTypeInstance).c_str()), delegateBindExpr->mTarget);
}
mResult = BfTypedValue();
@ -11810,7 +11813,10 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr)
SizedArray<BfIRType, 8> irParamTypes;
BfIRType irReturnType;
bindMethodInstance->GetIRFunctionInfo(mModule, irReturnType, irParamTypes);
methodInstance->GetIRFunctionInfo(mModule, irReturnType, irParamTypes);
int thisFuncParamIdx = methodInstance->GetThisIdx();
int thisBindParamIdx = methodInstance->GetThisIdx();
auto prevActiveFunction = mModule->mBfIRBuilder->GetActiveFunction();
auto prevInsertBlock = mModule->mBfIRBuilder->GetInsertBlock();

View file

@ -10769,8 +10769,16 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
if (accessorString.length() != 0)
{
methodName += " " + accessorString;
methodName += " ";
methodName += accessorString;
}
if ((methodNameFlags & BfMethodNameFlag_IncludeMut) != 0)
{
if ((methodDef->mIsMutating) && (methodInst->GetOwner()->IsValueType()))
methodName += " mut";
}
return methodName;
}

View file

@ -1298,15 +1298,6 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType,
}
}
// if ((paramIdx == 0) && (GetParamName(0) == "this") && (checkType->IsPointer()))
// {
// // We don't actually pass a this pointer for mut methods in valueless structs
// auto underlyingType = checkType->GetUnderlyingType();
// module->PopulateType(underlyingType, BfPopulateType_Data);
// if (underlyingType->IsValuelessType())
// continue;
// }
if (checkType->CanBeValuelessType())
module->PopulateType(checkType, BfPopulateType_Data);
if ((checkType->IsValuelessType()) && (!checkType->IsMethodRef()))

View file

@ -61,7 +61,8 @@ enum BfMethodNameFlags : uint8
BfMethodNameFlag_ResolveGenericParamNames = 1,
BfMethodNameFlag_OmitTypeName = 2,
BfMethodNameFlag_IncludeReturnType = 4,
BfMethodNameFlag_OmitParams = 8
BfMethodNameFlag_OmitParams = 8,
BfMethodNameFlag_IncludeMut = 0x10
};
enum BfGetMethodInstanceFlags : uint16