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

Properly fail enum case declarations outside enums

This commit is contained in:
Brian Fiete 2021-02-25 05:55:36 -08:00
parent d1d3af1cc0
commit 234aaa772c

View file

@ -3592,6 +3592,8 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
BfType* resolvedFieldType = NULL;
if (field->IsEnumCaseEntry())
{
if (typeInstance->IsEnum())
{
fieldInstance->mDataIdx = -(enumCaseEntryIdx++) - 1;
resolvedFieldType = typeInstance;
@ -3612,6 +3614,12 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
fieldInstance->mIsEnumPayloadCase = true;
}
}
else
{
Fail("Enum cases can only be declared within enum types", field->GetRefNode(), true);
resolvedFieldType = typeInstance;
}
}
else if ((field->mTypeRef != NULL) && ((field->mTypeRef->IsExact<BfVarTypeReference>()) || (field->mTypeRef->IsExact<BfLetTypeReference>()) || (field->mTypeRef->IsExact<BfExprModTypeRef>())))
{
resolvedFieldType = GetPrimitiveType(BfTypeCode_Var);