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:
parent
ba9d99fa76
commit
6a95cbb3b8
4 changed files with 26 additions and 20 deletions
|
@ -11140,8 +11140,7 @@ void BfExprEvaluator::Visit(BfCastExpression* castExpr)
|
||||||
bool BfExprEvaluator::IsExactMethodMatch(BfMethodInstance* methodA, BfMethodInstance* methodB, bool ignoreImplicitParams)
|
bool BfExprEvaluator::IsExactMethodMatch(BfMethodInstance* methodA, BfMethodInstance* methodB, bool ignoreImplicitParams)
|
||||||
{
|
{
|
||||||
if (methodA->mReturnType != methodB->mReturnType)
|
if (methodA->mReturnType != methodB->mReturnType)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int implicitParamCountA = methodA->GetImplicitParamCount();
|
int implicitParamCountA = methodA->GetImplicitParamCount();
|
||||||
if (methodA->HasExplicitThis())
|
if (methodA->HasExplicitThis())
|
||||||
implicitParamCountA++;
|
implicitParamCountA++;
|
||||||
|
@ -11703,7 +11702,11 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr)
|
||||||
}
|
}
|
||||||
else
|
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)
|
if (bindResult.mCheckedMultipleMethods)
|
||||||
{
|
{
|
||||||
|
@ -11711,8 +11714,8 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr)
|
||||||
mModule->TypeToString(delegateTypeInstance).c_str()), delegateBindExpr->mTarget);
|
mModule->TypeToString(delegateTypeInstance).c_str()), delegateBindExpr->mTarget);
|
||||||
}
|
}
|
||||||
else
|
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);
|
mModule->TypeToString(delegateTypeInstance).c_str()), delegateBindExpr->mTarget);
|
||||||
}
|
}
|
||||||
mResult = BfTypedValue();
|
mResult = BfTypedValue();
|
||||||
|
@ -11732,7 +11735,7 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasIncompatibleCallingConventions = !mModule->mSystem->IsCompatibleCallingConvention(methodInstance->mCallingConvention, bindMethodInstance->mCallingConvention);
|
bool hasIncompatibleCallingConventions = !mModule->mSystem->IsCompatibleCallingConvention(methodInstance->mCallingConvention, bindMethodInstance->mCallingConvention);
|
||||||
|
|
||||||
auto _GetInvokeMethodName = [&]()
|
auto _GetInvokeMethodName = [&]()
|
||||||
{
|
{
|
||||||
String methodName = "Invoke$";
|
String methodName = "Invoke$";
|
||||||
|
@ -11806,11 +11809,14 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr)
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
String methodName = _GetInvokeMethodName();
|
String methodName = _GetInvokeMethodName();
|
||||||
|
|
||||||
SizedArray<BfIRType, 8> irParamTypes;
|
SizedArray<BfIRType, 8> irParamTypes;
|
||||||
BfIRType irReturnType;
|
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 prevActiveFunction = mModule->mBfIRBuilder->GetActiveFunction();
|
||||||
auto prevInsertBlock = mModule->mBfIRBuilder->GetInsertBlock();
|
auto prevInsertBlock = mModule->mBfIRBuilder->GetInsertBlock();
|
||||||
|
|
|
@ -10524,7 +10524,7 @@ bool BfModule::HasMixin(BfTypeInstance* typeInstance, const StringImpl& methodNa
|
||||||
}
|
}
|
||||||
|
|
||||||
StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags methodNameFlags, BfTypeVector* typeGenericArgs, BfTypeVector* methodGenericArgs)
|
StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags methodNameFlags, BfTypeVector* typeGenericArgs, BfTypeVector* methodGenericArgs)
|
||||||
{
|
{
|
||||||
auto methodDef = methodInst->mMethodDef;
|
auto methodDef = methodInst->mMethodDef;
|
||||||
bool allowResolveGenericParamNames = ((methodNameFlags & BfMethodNameFlag_ResolveGenericParamNames) != 0);
|
bool allowResolveGenericParamNames = ((methodNameFlags & BfMethodNameFlag_ResolveGenericParamNames) != 0);
|
||||||
|
|
||||||
|
@ -10769,8 +10769,16 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
|
||||||
|
|
||||||
if (accessorString.length() != 0)
|
if (accessorString.length() != 0)
|
||||||
{
|
{
|
||||||
methodName += " " + accessorString;
|
methodName += " ";
|
||||||
|
methodName += accessorString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((methodNameFlags & BfMethodNameFlag_IncludeMut) != 0)
|
||||||
|
{
|
||||||
|
if ((methodDef->mIsMutating) && (methodInst->GetOwner()->IsValueType()))
|
||||||
|
methodName += " mut";
|
||||||
|
}
|
||||||
|
|
||||||
return methodName;
|
return methodName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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())
|
if (checkType->CanBeValuelessType())
|
||||||
module->PopulateType(checkType, BfPopulateType_Data);
|
module->PopulateType(checkType, BfPopulateType_Data);
|
||||||
if ((checkType->IsValuelessType()) && (!checkType->IsMethodRef()))
|
if ((checkType->IsValuelessType()) && (!checkType->IsMethodRef()))
|
||||||
|
|
|
@ -61,7 +61,8 @@ enum BfMethodNameFlags : uint8
|
||||||
BfMethodNameFlag_ResolveGenericParamNames = 1,
|
BfMethodNameFlag_ResolveGenericParamNames = 1,
|
||||||
BfMethodNameFlag_OmitTypeName = 2,
|
BfMethodNameFlag_OmitTypeName = 2,
|
||||||
BfMethodNameFlag_IncludeReturnType = 4,
|
BfMethodNameFlag_IncludeReturnType = 4,
|
||||||
BfMethodNameFlag_OmitParams = 8
|
BfMethodNameFlag_OmitParams = 8,
|
||||||
|
BfMethodNameFlag_IncludeMut = 0x10
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BfGetMethodInstanceFlags : uint16
|
enum BfGetMethodInstanceFlags : uint16
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue