mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Fixed false circular data ref with self-refing field function typeref
This commit is contained in:
parent
c34e6fe66a
commit
947426b384
3 changed files with 29 additions and 26 deletions
|
@ -6902,15 +6902,13 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (resolvedTypeRef->IsDelegateFromTypeRef() || resolvedTypeRef->IsFunctionFromTypeRef())
|
else if (resolvedTypeRef->IsDelegateFromTypeRef() || resolvedTypeRef->IsFunctionFromTypeRef())
|
||||||
{
|
{
|
||||||
auto delegateInfo = resolvedTypeRef->GetDelegateInfo();
|
auto delegateInfo = resolvedTypeRef->GetDelegateInfo();
|
||||||
auto invokeMethod = GetDelegateInvokeMethod(resolvedTypeRef->ToTypeInstance());
|
if (delegateInfo->mFunctionThisType != NULL)
|
||||||
|
AddDependency(delegateInfo->mFunctionThisType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference);
|
||||||
AddDependency(invokeMethod->mReturnType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference);
|
AddDependency(delegateInfo->mReturnType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference);
|
||||||
for (auto& param : invokeMethod->mParams)
|
for (auto& param : delegateInfo->mParams)
|
||||||
{
|
AddDependency(param, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference);
|
||||||
AddDependency(param.mResolvedType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BfTypeInstance* typeInstance = resolvedTypeRef->ToTypeInstance();
|
BfTypeInstance* typeInstance = resolvedTypeRef->ToTypeInstance();
|
||||||
|
@ -8864,7 +8862,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
|
||||||
|
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
|
|
||||||
auto returnType = ResolveTypeRef(delegateTypeRef->mReturnType);
|
auto returnType = ResolveTypeRef(delegateTypeRef->mReturnType, NULL, BfPopulateType_Declaration);
|
||||||
if (returnType == NULL)
|
if (returnType == NULL)
|
||||||
returnType = GetPrimitiveType(BfTypeCode_Var);
|
returnType = GetPrimitiveType(BfTypeCode_Var);
|
||||||
_CheckType(returnType);
|
_CheckType(returnType);
|
||||||
|
|
|
@ -3681,16 +3681,19 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
|
||||||
{
|
{
|
||||||
auto rhsDelegateType = BfNodeDynCastExact<BfDelegateTypeRef>(rhs);
|
auto rhsDelegateType = BfNodeDynCastExact<BfDelegateTypeRef>(rhs);
|
||||||
if (rhsDelegateType == NULL)
|
if (rhsDelegateType == NULL)
|
||||||
return false;
|
return false;
|
||||||
BfDelegateInfo* lhsDelegateType = lhs->GetDelegateInfo();
|
|
||||||
|
BfDelegateInfo* lhsDelegateInfo = lhs->GetDelegateInfo();
|
||||||
BfMethodInstance* lhsInvokeMethodInstance = ctx->mModule->GetRawMethodInstanceAtIdx(lhs->ToTypeInstance(), 0, "Invoke");
|
|
||||||
|
auto lhsTypeInstance = lhs->ToTypeInstance();
|
||||||
|
BfMethodDef* invokeMethodDef = lhsTypeInstance->mTypeDef->mMethods[0];
|
||||||
|
BF_ASSERT(invokeMethodDef->mName == "Invoke");
|
||||||
|
|
||||||
bool rhsIsDelegate = rhsDelegateType->mTypeToken->GetToken() == BfToken_Delegate;
|
bool rhsIsDelegate = rhsDelegateType->mTypeToken->GetToken() == BfToken_Delegate;
|
||||||
|
|
||||||
if ((lhs->IsDelegate()) != rhsIsDelegate)
|
if ((lhs->IsDelegate()) != rhsIsDelegate)
|
||||||
return false;
|
return false;
|
||||||
if (!Equals(lhsInvokeMethodInstance->mReturnType, rhsDelegateType->mReturnType, ctx))
|
if (!Equals(lhsDelegateInfo->mReturnType, rhsDelegateType->mReturnType, ctx))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool isMutating = true;
|
bool isMutating = true;
|
||||||
|
@ -3702,20 +3705,22 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
|
||||||
if ((param0->mNameNode != NULL) && (param0->mNameNode->Equals("this")))
|
if ((param0->mNameNode != NULL) && (param0->mNameNode->Equals("this")))
|
||||||
{
|
{
|
||||||
bool handled = false;
|
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));
|
auto rhsThisType = ctx->mModule->ResolveTypeRef(param0->mTypeRef, BfPopulateType_Identity, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_NoWarnOnMut | BfResolveTypeRefFlag_AllowRef));
|
||||||
if (rhsThisType->IsRef())
|
if (rhsThisType->IsRef())
|
||||||
{
|
{
|
||||||
if (!lhsThisType->IsPointer())
|
if (lhsThisType != rhsThisType->GetUnderlyingType())
|
||||||
|
return false;
|
||||||
|
if (!invokeMethodDef->mIsMutating)
|
||||||
return false;
|
return false;
|
||||||
if (lhsThisType->GetUnderlyingType() != rhsThisType->GetUnderlyingType())
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (lhsThisType != rhsThisType)
|
if (lhsThisType != rhsThisType)
|
||||||
return false;
|
return false;
|
||||||
|
if ((invokeMethodDef->mIsMutating) && (lhsThisType->IsValueType()))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
paramRefOfs = 1;
|
paramRefOfs = 1;
|
||||||
|
@ -3723,21 +3728,21 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rhsIsDelegate)
|
if (!rhsIsDelegate)
|
||||||
{
|
{
|
||||||
if (lhsInvokeMethodInstance->mMethodDef->mIsStatic != (paramRefOfs == 0))
|
if ((lhsDelegateInfo->mFunctionThisType == NULL) != (paramRefOfs == 0))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lhsInvokeMethodInstance->GetParamCount() != (int)rhsDelegateType->mParams.size() - paramRefOfs)
|
if (lhsDelegateInfo->mParams.size() != (int)rhsDelegateType->mParams.size() - paramRefOfs)
|
||||||
return false;
|
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;
|
return false;
|
||||||
StringView rhsParamName;
|
StringView rhsParamName;
|
||||||
if (rhsDelegateType->mParams[paramIdx + paramRefOfs]->mNameNode != NULL)
|
if (rhsDelegateType->mParams[paramIdx + paramRefOfs]->mNameNode != NULL)
|
||||||
rhsParamName = rhsDelegateType->mParams[paramIdx + paramRefOfs]->mNameNode->ToStringView();
|
rhsParamName = rhsDelegateType->mParams[paramIdx + paramRefOfs]->mNameNode->ToStringView();
|
||||||
if (lhsInvokeMethodInstance->GetParamName(paramIdx) != rhsParamName)
|
if (invokeMethodDef->mParams[paramIdx]->mName != rhsParamName)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -418,7 +418,7 @@ public:
|
||||||
Array<BfAstNode*> mDirectAllocNodes;
|
Array<BfAstNode*> mDirectAllocNodes;
|
||||||
BfType* mReturnType;
|
BfType* mReturnType;
|
||||||
BfType* mFunctionThisType;
|
BfType* mFunctionThisType;
|
||||||
Array<BfType*> mParams;
|
Array<BfType*> mParams;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BfDelegateInfo()
|
BfDelegateInfo()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue