mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 22:34:09 +02:00
Fixes to variable assignment detection
This commit is contained in:
parent
5277797d73
commit
4d1d972599
3 changed files with 60 additions and 19 deletions
|
@ -416,5 +416,38 @@ namespace IDETest
|
|||
}
|
||||
while (read > 0); //FAIL
|
||||
}
|
||||
|
||||
public void Local13()
|
||||
{
|
||||
int a = 123;
|
||||
int b;
|
||||
switch (a)
|
||||
{
|
||||
default: b = 0;
|
||||
}
|
||||
int c = b;
|
||||
}
|
||||
|
||||
public void Local14()
|
||||
{
|
||||
int a = 123;
|
||||
int b;
|
||||
switch (a)
|
||||
{
|
||||
default: b = 0; break;
|
||||
}
|
||||
int c = b;
|
||||
}
|
||||
|
||||
public void Local15()
|
||||
{
|
||||
int a = 123;
|
||||
int b;
|
||||
switch (a)
|
||||
{
|
||||
default: break;
|
||||
}
|
||||
int c = b; //FAIL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -326,8 +326,6 @@ void BfMethodState::ApplyDeferredLocalAssignData(const BfDeferredLocalAssignData
|
|||
BF_ASSERT(&deferredLocalAssignData != mDeferredLocalAssignData);
|
||||
|
||||
if (deferredLocalAssignData.mLeftBlockUncond)
|
||||
{
|
||||
if (mLeftBlockUncond)
|
||||
{
|
||||
for (int localIdx = 0; localIdx < (int)mLocals.size(); localIdx++)
|
||||
{
|
||||
|
@ -348,7 +346,6 @@ void BfMethodState::ApplyDeferredLocalAssignData(const BfDeferredLocalAssignData
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto& assignedLocal : deferredLocalAssignData.mAssignedLocals)
|
||||
|
|
|
@ -5061,12 +5061,20 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
|||
SetAndRestoreValue<BfDeferredLocalAssignData*> prevDLA(mCurMethodState->mDeferredLocalAssignData, &deferredLocalAssignDataVec[blockIdx]);
|
||||
mCurMethodState->mDeferredLocalAssignData->mVarIdBarrier = startingLocalVarId;
|
||||
|
||||
BfScopeData caseScopeData;
|
||||
caseScopeData.mOuterIsConditional = true;
|
||||
caseScopeData.mIsSharedTempBlock = true;
|
||||
mCurMethodState->AddScope(&caseScopeData);
|
||||
NewScopeState();
|
||||
|
||||
bool hadReturn = false;
|
||||
VisitCodeBlock(switchCase->mCodeBlock, BfIRBlock(), endBlock, BfIRBlock(), true, &hadReturn, switchStmt->mLabelNode);
|
||||
deferredLocalAssignDataVec[blockIdx].mHadReturn = hadReturn;
|
||||
caseCount++;
|
||||
if (!hadReturn)
|
||||
allHadReturns = false;
|
||||
|
||||
RestoreScopeState();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -5799,6 +5807,9 @@ void BfModule::Visit(BfRepeatStatement* repeatStmt)
|
|||
|
||||
RestoreScopeState();
|
||||
|
||||
prevDLA.Restore();
|
||||
mCurMethodState->ApplyDeferredLocalAssignData(deferredLocalAssignData);
|
||||
|
||||
if (isInfiniteLoop)
|
||||
EmitDefaultReturn();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue