mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Fixed exhaustive switch case test with const enums
This commit is contained in:
parent
5731b15b05
commit
63a87cbe57
2 changed files with 32 additions and 18 deletions
|
@ -4767,31 +4767,38 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
||||||
{
|
{
|
||||||
if (switchValue.mType->IsEnum())
|
if (switchValue.mType->IsEnum())
|
||||||
{
|
{
|
||||||
auto enumType = switchValue.mType->ToTypeInstance();
|
if (hadConstMatch)
|
||||||
if (enumType->IsPayloadEnum())
|
|
||||||
{
|
{
|
||||||
int lastTagId = -1;
|
// Already handled
|
||||||
for (auto& field : enumType->mFieldInstances)
|
|
||||||
{
|
|
||||||
auto fieldDef = field.GetFieldDef();
|
|
||||||
if (fieldDef == NULL)
|
|
||||||
continue;
|
|
||||||
if (field.mDataIdx < 0)
|
|
||||||
lastTagId = -field.mDataIdx - 1;
|
|
||||||
}
|
|
||||||
isComprehensive = lastTagId == (int)handledCases.size() - 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (auto& field : enumType->mFieldInstances)
|
auto enumType = switchValue.mType->ToTypeInstance();
|
||||||
|
if (enumType->IsPayloadEnum())
|
||||||
{
|
{
|
||||||
auto fieldDef = field.GetFieldDef();
|
int lastTagId = -1;
|
||||||
if ((fieldDef != NULL) && (fieldDef->mFieldDeclaration != NULL) && (fieldDef->mFieldDeclaration->mTypeRef == NULL))
|
for (auto& field : enumType->mFieldInstances)
|
||||||
{
|
{
|
||||||
if (field.mConstIdx != -1)
|
auto fieldDef = field.GetFieldDef();
|
||||||
|
if (fieldDef == NULL)
|
||||||
|
continue;
|
||||||
|
if (field.mDataIdx < 0)
|
||||||
|
lastTagId = -field.mDataIdx - 1;
|
||||||
|
}
|
||||||
|
isComprehensive = lastTagId == (int)handledCases.size() - 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (auto& field : enumType->mFieldInstances)
|
||||||
|
{
|
||||||
|
auto fieldDef = field.GetFieldDef();
|
||||||
|
if ((fieldDef != NULL) && (fieldDef->mFieldDeclaration != NULL) && (fieldDef->mFieldDeclaration->mTypeRef == NULL))
|
||||||
{
|
{
|
||||||
auto constant = enumType->mConstHolder->GetConstantById(field.mConstIdx);
|
if (field.mConstIdx != -1)
|
||||||
isComprehensive &= handledCases.ContainsKey(constant->mInt64);
|
{
|
||||||
|
auto constant = enumType->mConstHolder->GetConstantById(field.mConstIdx);
|
||||||
|
isComprehensive &= handledCases.ContainsKey(constant->mInt64);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,13 @@ namespace Tests
|
||||||
}
|
}
|
||||||
Test.Assert(val == 0);
|
Test.Assert(val == 0);
|
||||||
|
|
||||||
|
const EnumA cea = .A;
|
||||||
|
switch (cea)
|
||||||
|
{
|
||||||
|
case .A:
|
||||||
|
val = 123;
|
||||||
|
}
|
||||||
|
|
||||||
ee = .B(10);
|
ee = .B(10);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue