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

Fixed circular ref data failure in 'using' field

This commit is contained in:
Brian Fiete 2022-07-15 08:37:04 -04:00
parent e28b9c8325
commit 45deac0ba3
2 changed files with 32 additions and 13 deletions

View file

@ -47,6 +47,7 @@ enum BfPopulateType
BfPopulateType_Interfaces_Direct, BfPopulateType_Interfaces_Direct,
BfPopulateType_AllowStaticMethods, BfPopulateType_AllowStaticMethods,
BfPopulateType_Interfaces_All, BfPopulateType_Interfaces_All,
BfPopulateType_Data_Soft,
BfPopulateType_Data, BfPopulateType_Data,
BfPopulateType_DataAndMethods, BfPopulateType_DataAndMethods,
BfPopulateType_Full = BfPopulateType_DataAndMethods, BfPopulateType_Full = BfPopulateType_DataAndMethods,
@ -1609,7 +1610,7 @@ public:
BfError* Warn(int warningNum, const StringImpl& warning, BfAstNode* refNode = NULL, bool isPersistent = false, bool showInSpecialized = false); BfError* Warn(int warningNum, const StringImpl& warning, BfAstNode* refNode = NULL, bool isPersistent = false, bool showInSpecialized = false);
void CheckErrorAttributes(BfTypeInstance* typeInstance, BfMethodInstance* methodInstance, BfCustomAttributes* customAttributes, BfAstNode* targetSrc); void CheckErrorAttributes(BfTypeInstance* typeInstance, BfMethodInstance* methodInstance, BfCustomAttributes* customAttributes, BfAstNode* targetSrc);
void CheckRangeError(BfType* type, BfAstNode* refNode); void CheckRangeError(BfType* type, BfAstNode* refNode);
bool CheckCircularDataError(); bool CheckCircularDataError(bool failTypes = true);
BfFileInstance* GetFileFromNode(BfAstNode* astNode); BfFileInstance* GetFileFromNode(BfAstNode* astNode);
//void UpdateSrcPos(BfAstNode* astNode, bool setDebugLoc = true, int debugLocOffset = 0, bool force = false); //void UpdateSrcPos(BfAstNode* astNode, bool setDebugLoc = true, int debugLocOffset = 0, bool force = false);
void UpdateSrcPos(BfAstNode* astNode, BfSrcPosFlags flags = BfSrcPosFlag_None, int debugLocOffset = 0); void UpdateSrcPos(BfAstNode* astNode, BfSrcPosFlags flags = BfSrcPosFlag_None, int debugLocOffset = 0);

View file

@ -1038,7 +1038,7 @@ void BfModule::TypeFailed(BfTypeInstance* typeInstance)
mHadBuildError = true; mHadBuildError = true;
} }
bool BfModule::CheckCircularDataError() bool BfModule::CheckCircularDataError(bool failTypes)
{ {
// Find two loops of mCurTypeInstance. Just finding one loop can give some false errors. // Find two loops of mCurTypeInstance. Just finding one loop can give some false errors.
@ -1104,10 +1104,13 @@ bool BfModule::CheckCircularDataError()
((checkTypeState->mType == NULL) || (checkTypeState->mType->IsTypeInstance()))) ((checkTypeState->mType == NULL) || (checkTypeState->mType->IsTypeInstance())))
return hadError; return hadError;
hadError = true;
if (!failTypes)
return hadError;
// We only get one chance to fire off these errors, they can't be ignored. // We only get one chance to fire off these errors, they can't be ignored.
SetAndRestoreValue<bool> prevIgnoreErrors(mIgnoreErrors, false); SetAndRestoreValue<bool> prevIgnoreErrors(mIgnoreErrors, false);
hadError = true;
if (checkTypeState->mCurAttributeTypeRef != NULL) if (checkTypeState->mCurAttributeTypeRef != NULL)
{ {
Fail(StrFormat("Attribute type '%s' causes a data cycle", BfTypeUtils::TypeToString(checkTypeState->mCurAttributeTypeRef).c_str()), checkTypeState->mCurAttributeTypeRef, true); Fail(StrFormat("Attribute type '%s' causes a data cycle", BfTypeUtils::TypeToString(checkTypeState->mCurAttributeTypeRef).c_str()), checkTypeState->mCurAttributeTypeRef, true);
@ -3138,15 +3141,14 @@ void BfModule::PopulateUsingFieldData(BfTypeInstance* typeInstance)
checkTypeState = checkTypeState->mPrevState; checkTypeState = checkTypeState->mPrevState;
} }
if (isPopulatingType) if (!isPopulatingType)
{
typeInstance->mTypeInfoEx->mUsingFieldData->mAwaitingPopulateSet.Add(usingType);
}
else
{ {
// We need to populate this type now // We need to populate this type now
PopulateType(usingType); PopulateType(usingType, BfPopulateType_Data_Soft);
} }
if (usingType->mDefineState < BfTypeDefineState_Defined)
typeInstance->mTypeInfoEx->mUsingFieldData->mAwaitingPopulateSet.Add(usingType);
} }
auto fieldInstance = &usingType->mFieldInstances[fieldDef->mIdx]; auto fieldInstance = &usingType->mFieldInstances[fieldDef->mIdx];
@ -3777,7 +3779,15 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
} }
if (!typeInstance->mTypeFailed) if (!typeInstance->mTypeFailed)
{
if (populateType == BfPopulateType_Data_Soft)
{
if (CheckCircularDataError(false))
return;
}
CheckCircularDataError(); CheckCircularDataError();
}
if (typeInstance->mDefineState < BfTypeDefineState_Declaring) if (typeInstance->mDefineState < BfTypeDefineState_Declaring)
{ {
@ -4894,6 +4904,8 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
if (typeInstance->mResolvingConstField) if (typeInstance->mResolvingConstField)
return; return;
bool hadSoftFail = false;
for (auto& fieldInstanceRef : typeInstance->mFieldInstances) for (auto& fieldInstanceRef : typeInstance->mFieldInstances)
{ {
auto fieldInstance = &fieldInstanceRef; auto fieldInstance = &fieldInstanceRef;
@ -4947,9 +4959,14 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
SetAndRestoreValue<BfFieldDef*> prevTypeRef(mContext->mCurTypeState->mCurFieldDef, fieldDef); SetAndRestoreValue<BfFieldDef*> prevTypeRef(mContext->mCurTypeState->mCurFieldDef, fieldDef);
bool populateChildType = !typeInstance->mTypeFailed; bool populateChildType = !typeInstance->mTypeFailed;
//bool populateChildType = true; //bool populateChildType = true;
PopulateType(resolvedFieldType, populateChildType ? BfPopulateType_Data : BfPopulateType_Declaration); PopulateType(resolvedFieldType, populateChildType ? ((populateType == BfPopulateType_Data_Soft) ? BfPopulateType_Data_Soft : BfPopulateType_Data) : BfPopulateType_Declaration);
if (populateChildType) if (populateType == BfPopulateType_Data_Soft)
{
if (resolvedFieldType->IsDataIncomplete())
hadSoftFail = true;
}
else if (populateChildType)
{ {
if (resolvedFieldType->IsFinishingType()) if (resolvedFieldType->IsFinishingType())
{ {
@ -4971,10 +4988,11 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
} }
} }
} }
} }
if (hadSoftFail)
return;
bool tryCE = true; bool tryCE = true;
if (typeInstance->mDefineState == BfTypeDefineState_CETypeInit) if (typeInstance->mDefineState == BfTypeDefineState_CETypeInit)
{ {