mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Fixed payload enum switch 'case .A:' after a 'case .A(let value):'
This commit is contained in:
parent
11bde5caf2
commit
71dc0ab9d7
2 changed files with 47 additions and 6 deletions
|
@ -4640,6 +4640,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
|||
bool prevHadFallthrough = false;
|
||||
|
||||
Dictionary<int64, _CaseState> handledCases;
|
||||
HashSet<int64> condCases;
|
||||
for (BfSwitchCase* switchCase : switchStmt->mSwitchCases)
|
||||
{
|
||||
deferredLocalAssignDataVec[blockIdx].mScopeData = mCurMethodState->mCurScope;
|
||||
|
@ -4810,22 +4811,42 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
|||
}
|
||||
else if ((constantInt != NULL) && (!hadWhen) && (!isConstSwitch))
|
||||
{
|
||||
if (!hadConditional)
|
||||
if (hadConditional)
|
||||
{
|
||||
condCases.Add(constantInt->mInt64);
|
||||
}
|
||||
else
|
||||
{
|
||||
_CaseState* caseState = NULL;
|
||||
handledCases.TryAdd(constantInt->mInt64, NULL, &caseState);
|
||||
|
||||
if (caseState->mUncondBlock)
|
||||
if (condCases.Contains(constantInt->mInt64))
|
||||
{
|
||||
_ShowCaseError(constantInt->mInt64, caseExpr);
|
||||
// This is a 'case .A:' after a 'case .A(let value):'
|
||||
eqResult = mBfIRBuilder->CreateCmpEQ(enumTagVal.mValue, caseValue.mValue);
|
||||
notEqBB = mBfIRBuilder->CreateBlock(StrFormat("switch.notEq.%d", blockIdx));
|
||||
|
||||
mayHaveMatch = true;
|
||||
mBfIRBuilder->CreateCondBr(eqResult, caseBlock, notEqBB);
|
||||
|
||||
mBfIRBuilder->AddBlock(notEqBB);
|
||||
mBfIRBuilder->SetInsertPoint(notEqBB);
|
||||
}
|
||||
else
|
||||
{
|
||||
caseState->mUncondBlock = doBlock;
|
||||
mBfIRBuilder->AddSwitchCase(switchStatement, caseIntVal.mValue, doBlock);
|
||||
hadConstIntVals = true;
|
||||
if (caseState->mUncondBlock)
|
||||
{
|
||||
_ShowCaseError(constantInt->mInt64, caseExpr);
|
||||
}
|
||||
else
|
||||
{
|
||||
caseState->mUncondBlock = doBlock;
|
||||
mBfIRBuilder->AddSwitchCase(switchStatement, caseIntVal.mValue, doBlock);
|
||||
hadConstIntVals = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mayHaveMatch = true;
|
||||
}
|
||||
else if (!handled)
|
||||
|
|
|
@ -112,6 +112,26 @@ namespace Tests
|
|||
Test.Assert(false);
|
||||
}
|
||||
|
||||
switch (ee)
|
||||
{
|
||||
case .B(123):
|
||||
Test.Assert(true);
|
||||
case .B:
|
||||
Test.Assert(false);
|
||||
default:
|
||||
Test.Assert(false);
|
||||
}
|
||||
|
||||
switch (ee)
|
||||
{
|
||||
case .A:
|
||||
case .B(123):
|
||||
Test.Assert(true);
|
||||
case .B:
|
||||
Test.Assert(false);
|
||||
case .C:
|
||||
}
|
||||
|
||||
EnumF ef = .EE(.C(3, 4));
|
||||
switch (ef)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue