mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Fixed const handling
This commit is contained in:
parent
395cac905d
commit
67556c2ff6
1 changed files with 18 additions and 15 deletions
|
@ -3615,8 +3615,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check enum cases for duplicates
|
// Const handling
|
||||||
if (mCurTypeInstance->IsEnum())
|
|
||||||
{
|
{
|
||||||
Dictionary<int64, BfFieldDef*> valueMap;
|
Dictionary<int64, BfFieldDef*> valueMap;
|
||||||
for (auto& fieldInstanceRef : typeInstance->mFieldInstances)
|
for (auto& fieldInstanceRef : typeInstance->mFieldInstances)
|
||||||
|
@ -3632,22 +3631,26 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
||||||
SetAndRestoreValue<BfFieldDef*> prevTypeRef(mContext->mCurTypeState->mCurFieldDef, fieldDef);
|
SetAndRestoreValue<BfFieldDef*> prevTypeRef(mContext->mCurTypeState->mCurFieldDef, fieldDef);
|
||||||
typeInstance->mModule->ResolveConstField(typeInstance, fieldInstance, fieldDef);
|
typeInstance->mModule->ResolveConstField(typeInstance, fieldInstance, fieldDef);
|
||||||
|
|
||||||
auto underlyingType = fieldInstance->mResolvedType->GetUnderlyingType();
|
// Check enum cases for duplicates
|
||||||
if ((fieldDef->IsEnumCaseEntry()) && (fieldInstance->mConstIdx != -1) && (underlyingType->IsIntegral()))
|
if (mCurTypeInstance->IsEnum())
|
||||||
{
|
{
|
||||||
auto foreignConst = typeInstance->mConstHolder->GetConstantById(fieldInstance->mConstIdx);
|
auto underlyingType = fieldInstance->mResolvedType->GetUnderlyingType();
|
||||||
BfFieldDef** fieldDefPtr;
|
if ((fieldDef->IsEnumCaseEntry()) && (fieldInstance->mConstIdx != -1) && (underlyingType->IsIntegral()))
|
||||||
if (valueMap.TryAdd(foreignConst->mInt64, NULL, &fieldDefPtr))
|
|
||||||
{
|
{
|
||||||
*fieldDefPtr = fieldDef;
|
auto foreignConst = typeInstance->mConstHolder->GetConstantById(fieldInstance->mConstIdx);
|
||||||
|
BfFieldDef** fieldDefPtr;
|
||||||
|
if (valueMap.TryAdd(foreignConst->mInt64, NULL, &fieldDefPtr))
|
||||||
|
{
|
||||||
|
*fieldDefPtr = fieldDef;
|
||||||
|
}
|
||||||
|
else if ((typeInstance->mCustomAttributes == NULL) || (typeInstance->mCustomAttributes->Get(mCompiler->mAllowDuplicatesAttributeTypeDef) == NULL))
|
||||||
|
{
|
||||||
|
auto error = Warn(0, StrFormat("Enum value '%lld' for field '%s' is not unique. Considering adding [AllowDuplicates] to the type declaration.", foreignConst->mInt64, fieldDef->mName.c_str()), fieldDef->GetRefNode(), true);
|
||||||
|
if (error != NULL)
|
||||||
|
mCompiler->mPassInstance->MoreInfo(StrFormat("This value was previously used for field '%s'", (*fieldDefPtr)->mName.c_str()), (*fieldDefPtr)->GetRefNode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ((typeInstance->mCustomAttributes == NULL) || (typeInstance->mCustomAttributes->Get(mCompiler->mAllowDuplicatesAttributeTypeDef) == NULL))
|
}
|
||||||
{
|
|
||||||
auto error = Warn(0, StrFormat("Enum value '%lld' for field '%s' is not unique. Considering adding [AllowDuplicates] to the type declaration.", foreignConst->mInt64, fieldDef->mName.c_str()), fieldDef->GetRefNode(), true);
|
|
||||||
if (error != NULL)
|
|
||||||
mCompiler->mPassInstance->MoreInfo(StrFormat("This value was previously used for field '%s'", (*fieldDefPtr)->mName.c_str()), (*fieldDefPtr)->GetRefNode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue