mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -327,27 +327,24 @@ void BfMethodState::ApplyDeferredLocalAssignData(const BfDeferredLocalAssignData
|
|||
|
||||
if (deferredLocalAssignData.mLeftBlockUncond)
|
||||
{
|
||||
if (mLeftBlockUncond)
|
||||
for (int localIdx = 0; localIdx < (int)mLocals.size(); localIdx++)
|
||||
{
|
||||
for (int localIdx = 0; localIdx < (int)mLocals.size(); localIdx++)
|
||||
auto localDef = mLocals[localIdx];
|
||||
if (localDef->mAssignedKind == BfLocalVarAssignKind_None)
|
||||
{
|
||||
auto localDef = mLocals[localIdx];
|
||||
if (localDef->mAssignedKind == BfLocalVarAssignKind_None)
|
||||
bool hadAssignment = false;
|
||||
if (mDeferredLocalAssignData != NULL)
|
||||
{
|
||||
bool hadAssignment = false;
|
||||
if (mDeferredLocalAssignData != NULL)
|
||||
{
|
||||
for (auto& entry : mDeferredLocalAssignData->mAssignedLocals)
|
||||
if (entry.mLocalVar == localDef)
|
||||
hadAssignment = true;
|
||||
}
|
||||
if (!hadAssignment)
|
||||
{
|
||||
LocalDefined(localDef);
|
||||
}
|
||||
for (auto& entry : mDeferredLocalAssignData->mAssignedLocals)
|
||||
if (entry.mLocalVar == localDef)
|
||||
hadAssignment = true;
|
||||
}
|
||||
if (!hadAssignment)
|
||||
{
|
||||
LocalDefined(localDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -5054,19 +5054,27 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
|||
if (switchCase->mCodeBlock != NULL)
|
||||
{
|
||||
isComprehensive = true;
|
||||
UpdateSrcPos(switchCase->mCodeBlock);
|
||||
|
||||
UpdateSrcPos(switchCase->mCodeBlock);
|
||||
|
||||
deferredLocalAssignDataVec[blockIdx].mScopeData = mCurMethodState->mCurScope;
|
||||
deferredLocalAssignDataVec[blockIdx].ExtendFrom(mCurMethodState->mDeferredLocalAssignData);
|
||||
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
|
||||
|
@ -5796,9 +5804,12 @@ 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