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

Fixed detection of data cycles within unions

This commit is contained in:
Brian Fiete 2020-05-13 07:42:57 -07:00
parent 706153348a
commit 577cd2e270
3 changed files with 27 additions and 3 deletions

View file

@ -114,7 +114,8 @@ public:
{
ResolveKind_None,
ResolveKind_BuildingGenericParams,
ResolveKind_ResolvingVarType
ResolveKind_ResolvingVarType,
ResolveKind_UnionInnerType,
};
public:

View file

@ -704,6 +704,12 @@ bool BfModule::CheckCircularDataError()
if (checkTypeState == NULL)
return hadError;
if (checkTypeState->mResolveKind == BfTypeState::ResolveKind_UnionInnerType)
{
checkTypeState = checkTypeState->mPrevState;
continue;
}
if (isPreBaseCheck)
{
if (checkTypeState->mPopulateType != BfPopulateType_Declaration)
@ -729,7 +735,15 @@ bool BfModule::CheckCircularDataError()
{
if (checkTypeState == NULL)
return hadError;
if ((checkTypeState->mCurAttributeTypeRef == NULL) && (checkTypeState->mCurBaseTypeRef == NULL) && (checkTypeState->mCurFieldDef == NULL))
if (checkTypeState->mResolveKind == BfTypeState::ResolveKind_UnionInnerType)
{
// Skip over this to actual data references
checkTypeState = checkTypeState->mPrevState;
continue;
}
if ((checkTypeState->mCurAttributeTypeRef == NULL) && (checkTypeState->mCurBaseTypeRef == NULL) && (checkTypeState->mCurFieldDef == NULL) )
return hadError;
// We only get one chance to fire off these errors, they can't be ignored.
@ -2762,7 +2776,10 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
}
}
if (typeInstance->mIsUnion)
{
SetAndRestoreValue<BfTypeState::ResolveKind> prevResolveKind(typeState.mResolveKind, BfTypeState::ResolveKind_UnionInnerType);
unionInnerType = typeInstance->GetUnionInnerType();
}
if (!isOrdered)
{

View file

@ -1283,6 +1283,10 @@ BfType* BfTypeInstance::GetUnionInnerType(bool* wantSplat)
if (!mIsUnion)
return NULL;
BfTypeState typeState(this, mContext->mCurTypeState);
typeState.mPopulateType = BfPopulateType_Data;
SetAndRestoreValue<BfTypeState*> prevTypeState(mContext->mCurTypeState, &typeState);
int unionSize = 0;
BfType* unionInnerType = NULL;
bool makeRaw = false;
@ -1309,6 +1313,8 @@ BfType* BfTypeInstance::GetUnionInnerType(bool* wantSplat)
if (checkInnerType != NULL)
{
SetAndRestoreValue<BfFieldDef*> prevTypeRef(mContext->mCurTypeState->mCurFieldDef, fieldDef);
mModule->PopulateType(checkInnerType);
if (checkInnerType->mSize > unionSize)
unionSize = checkInnerType->mSize;