1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Fixed false circular data ref with self-refing field function typeref

This commit is contained in:
Brian Fiete 2020-09-10 10:42:32 -07:00
parent c34e6fe66a
commit 947426b384
3 changed files with 29 additions and 26 deletions

View file

@ -6902,15 +6902,13 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy
}
}
else if (resolvedTypeRef->IsDelegateFromTypeRef() || resolvedTypeRef->IsFunctionFromTypeRef())
{
{
auto delegateInfo = resolvedTypeRef->GetDelegateInfo();
auto invokeMethod = GetDelegateInvokeMethod(resolvedTypeRef->ToTypeInstance());
AddDependency(invokeMethod->mReturnType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference);
for (auto& param : invokeMethod->mParams)
{
AddDependency(param.mResolvedType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference);
}
if (delegateInfo->mFunctionThisType != NULL)
AddDependency(delegateInfo->mFunctionThisType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference);
AddDependency(delegateInfo->mReturnType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference);
for (auto& param : delegateInfo->mParams)
AddDependency(param, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference);
}
BfTypeInstance* typeInstance = resolvedTypeRef->ToTypeInstance();
@ -8864,7 +8862,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
bool failed = false;
auto returnType = ResolveTypeRef(delegateTypeRef->mReturnType);
auto returnType = ResolveTypeRef(delegateTypeRef->mReturnType, NULL, BfPopulateType_Declaration);
if (returnType == NULL)
returnType = GetPrimitiveType(BfTypeCode_Var);
_CheckType(returnType);

View file

@ -3681,16 +3681,19 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
{
auto rhsDelegateType = BfNodeDynCastExact<BfDelegateTypeRef>(rhs);
if (rhsDelegateType == NULL)
return false;
BfDelegateInfo* lhsDelegateType = lhs->GetDelegateInfo();
BfMethodInstance* lhsInvokeMethodInstance = ctx->mModule->GetRawMethodInstanceAtIdx(lhs->ToTypeInstance(), 0, "Invoke");
return false;
BfDelegateInfo* lhsDelegateInfo = lhs->GetDelegateInfo();
auto lhsTypeInstance = lhs->ToTypeInstance();
BfMethodDef* invokeMethodDef = lhsTypeInstance->mTypeDef->mMethods[0];
BF_ASSERT(invokeMethodDef->mName == "Invoke");
bool rhsIsDelegate = rhsDelegateType->mTypeToken->GetToken() == BfToken_Delegate;
if ((lhs->IsDelegate()) != rhsIsDelegate)
return false;
if (!Equals(lhsInvokeMethodInstance->mReturnType, rhsDelegateType->mReturnType, ctx))
if (!Equals(lhsDelegateInfo->mReturnType, rhsDelegateType->mReturnType, ctx))
return false;
bool isMutating = true;
@ -3702,20 +3705,22 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
if ((param0->mNameNode != NULL) && (param0->mNameNode->Equals("this")))
{
bool handled = false;
auto lhsThisType = lhsInvokeMethodInstance->GetParamType(-1);
auto lhsThisType = lhsDelegateInfo->mFunctionThisType;
auto rhsThisType = ctx->mModule->ResolveTypeRef(param0->mTypeRef, BfPopulateType_Identity, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_NoWarnOnMut | BfResolveTypeRefFlag_AllowRef));
if (rhsThisType->IsRef())
{
if (!lhsThisType->IsPointer())
{
if (lhsThisType != rhsThisType->GetUnderlyingType())
return false;
if (!invokeMethodDef->mIsMutating)
return false;
if (lhsThisType->GetUnderlyingType() != rhsThisType->GetUnderlyingType())
return false;
}
else
{
if (lhsThisType != rhsThisType)
return false;
if ((invokeMethodDef->mIsMutating) && (lhsThisType->IsValueType()))
return false;
}
paramRefOfs = 1;
@ -3723,21 +3728,21 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
}
if (!rhsIsDelegate)
{
if (lhsInvokeMethodInstance->mMethodDef->mIsStatic != (paramRefOfs == 0))
{
if ((lhsDelegateInfo->mFunctionThisType == NULL) != (paramRefOfs == 0))
return false;
}
if (lhsInvokeMethodInstance->GetParamCount() != (int)rhsDelegateType->mParams.size() - paramRefOfs)
if (lhsDelegateInfo->mParams.size() != (int)rhsDelegateType->mParams.size() - paramRefOfs)
return false;
for (int paramIdx = 0; paramIdx < lhsInvokeMethodInstance->GetParamCount(); paramIdx++)
for (int paramIdx = 0; paramIdx < lhsDelegateInfo->mParams.size(); paramIdx++)
{
if (!Equals(lhsInvokeMethodInstance->GetParamType(paramIdx), rhsDelegateType->mParams[paramIdx + paramRefOfs]->mTypeRef, ctx))
if (!Equals(lhsDelegateInfo->mParams[paramIdx], rhsDelegateType->mParams[paramIdx + paramRefOfs]->mTypeRef, ctx))
return false;
StringView rhsParamName;
if (rhsDelegateType->mParams[paramIdx + paramRefOfs]->mNameNode != NULL)
rhsParamName = rhsDelegateType->mParams[paramIdx + paramRefOfs]->mNameNode->ToStringView();
if (lhsInvokeMethodInstance->GetParamName(paramIdx) != rhsParamName)
if (invokeMethodDef->mParams[paramIdx]->mName != rhsParamName)
return false;
}
return true;

View file

@ -418,7 +418,7 @@ public:
Array<BfAstNode*> mDirectAllocNodes;
BfType* mReturnType;
BfType* mFunctionThisType;
Array<BfType*> mParams;
Array<BfType*> mParams;
public:
BfDelegateInfo()