mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Improved variable assignment detection in local methods
This commit is contained in:
parent
d43c47f866
commit
3739020504
2 changed files with 29 additions and 14 deletions
|
@ -22502,10 +22502,18 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth
|
|||
}
|
||||
}
|
||||
|
||||
// Keep outs for being marked as assigned
|
||||
// Keep outs from being marked as assigned
|
||||
auto rootMethodState = mCurMethodState->GetRootMethodState();
|
||||
BfDeferredLocalAssignData deferredLocalAssignData(rootMethodState->mCurScope);
|
||||
deferredLocalAssignData.mVarIdBarrier = rootMethodState->mCurLocalVarId;
|
||||
if (rootMethodState->mDeferredLocalAssignData != NULL)
|
||||
{
|
||||
auto prevDLA = rootMethodState->mDeferredLocalAssignData;
|
||||
while ((prevDLA != NULL) && (prevDLA->mIsChained))
|
||||
prevDLA = prevDLA->mChainedAssignData;
|
||||
deferredLocalAssignData.mAssignedLocals = prevDLA->mAssignedLocals;
|
||||
deferredLocalAssignData.mLeftBlockUncond = prevDLA->mLeftBlockUncond;
|
||||
}
|
||||
SetAndRestoreValue<BfDeferredLocalAssignData*> prevDLA(rootMethodState->mDeferredLocalAssignData, &deferredLocalAssignData);
|
||||
if (!mIgnoreErrors)
|
||||
localMethod->mDidBodyErrorPass = true;
|
||||
|
|
|
@ -347,22 +347,29 @@ namespace Tests
|
|||
public static void TestL()
|
||||
{
|
||||
int a = 8;
|
||||
int b;
|
||||
|
||||
int LocalA()
|
||||
if (a == 8)
|
||||
{
|
||||
return 9;
|
||||
b = 9;
|
||||
|
||||
int LocalA()
|
||||
{
|
||||
return 9;
|
||||
}
|
||||
|
||||
int LocalB()
|
||||
{
|
||||
int q = b;
|
||||
return a;
|
||||
}
|
||||
|
||||
function int() func = => LocalA;
|
||||
Test.Assert(func() == 9);
|
||||
|
||||
delegate int() dlg = scope => LocalB;
|
||||
Test.Assert(dlg() == 8);
|
||||
}
|
||||
|
||||
int LocalB()
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
function int() func = => LocalA;
|
||||
Test.Assert(func() == 9);
|
||||
|
||||
delegate int() dlg = scope => LocalB;
|
||||
Test.Assert(dlg() == 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue