mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Fallthrough fixes for destructuring and allHadReturns
This commit is contained in:
parent
fa6bdc0d04
commit
5e9ac07804
3 changed files with 54 additions and 1 deletions
|
@ -3621,6 +3621,8 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i
|
|||
VisitEmbeddedStatement(ifStmt->mTrueStatement);
|
||||
}
|
||||
prevDLA.Restore();
|
||||
if (mCurMethodState->mDeferredLocalAssignData != NULL)
|
||||
mCurMethodState->mDeferredLocalAssignData->mLeftBlock = deferredLocalAssignData.mLeftBlock;
|
||||
|
||||
bool trueHadReturn = mCurMethodState->mHadReturn;
|
||||
|
||||
|
@ -4365,6 +4367,14 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
|||
hadWhen = true;
|
||||
whenExpr = checkWhenExpr;
|
||||
}
|
||||
|
||||
if (auto invocationExpr = BfNodeDynCast<BfInvocationExpression>(caseExpr))
|
||||
{
|
||||
if (prevHadFallthrough)
|
||||
{
|
||||
Fail("Destructuring cannot be used when the previous case contains a fallthrough", caseExpr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BfIRBlock lastNotEqBlock;
|
||||
|
@ -4664,7 +4674,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
|||
openedScope = false;
|
||||
deferredLocalAssignDataVec[blockIdx].mHadReturn = hadReturn;
|
||||
caseCount++;
|
||||
if ((!hadReturn) && (!mCurMethodState->mDeferredLocalAssignData->mHadFallthrough))
|
||||
if ((!hadReturn) &&
|
||||
((!mCurMethodState->mDeferredLocalAssignData->mHadFallthrough) || (mCurMethodState->mDeferredLocalAssignData->mLeftBlock)))
|
||||
allHadReturns = false;
|
||||
|
||||
if (auto block = BfNodeDynCast<BfBlock>(switchCase->mCodeBlock))
|
||||
|
|
18
IDEHelper/Tests/src/Switches.bf
Normal file
18
IDEHelper/Tests/src/Switches.bf
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
class Switches
|
||||
{
|
||||
int Switch0(Result<int> res)
|
||||
{
|
||||
switch (res)
|
||||
{
|
||||
case .Ok(let a):
|
||||
return 0;
|
||||
case .Err(let b):
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue