1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 20:12:21 +02:00

Fixed processing of valueless lambda inside allocated lambda

This commit is contained in:
Brian Fiete 2021-12-30 09:52:49 -05:00
parent 0eb19245eb
commit b3d3f0fb54
2 changed files with 133 additions and 90 deletions

View file

@ -18055,6 +18055,8 @@ void BfModule::ProcessMethod_ProcessDeferredLocals(int startIdx)
// if (mCurMethodState->mPrevMethodState != NULL) // Re-entry
// return;
auto startMethodState = mCurMethodState;
auto _ClearState = [&]()
{
mCurMethodState->mLocalMethods.Clear();
@ -18065,6 +18067,9 @@ void BfModule::ProcessMethod_ProcessDeferredLocals(int startIdx)
mCurMethodState->mLocalVarSet.Clear();
};
while (true)
{
bool didWork = false;
// Don't process local methods if we had a build error - this isn't just an optimization, it keeps us from showing the same error twice since
// we show errors in the capture phase. If we somehow pass the capture phase without error then this method WILL show any errors here,
// however (compiler bug), so this is the safest way
@ -18110,7 +18115,10 @@ void BfModule::ProcessMethod_ProcessDeferredLocals(int startIdx)
delete deferredLocalMethod;
mContext->CheckLockYield();
didWork = true;
}
mCurMethodState->mDeferredLocalMethods.Clear();
}
for (auto& kv : mCurMethodState->mLocalMethodCache)
@ -18168,13 +18176,23 @@ void BfModule::ProcessMethod_ProcessDeferredLocals(int startIdx)
if (lambdaInstance->mDtorMethodInstance != NULL)
{
lambdaInstance->mDtorMethodInstance->mMethodInstanceGroup = &methodInstanceGroup;
auto startMethodState2 = mCurMethodState;
ProcessMethod(lambdaInstance->mDtorMethodInstance);
lambdaInstance->mDtorMethodInstance->mMethodInstanceGroup = NULL;
}
}
didWork = true;
}
mContext->CheckLockYield();
mCurMethodState->mDeferredLambdaInstances.Clear();
}
if (!didWork)
break;
}
}

View file

@ -116,6 +116,22 @@ namespace Tests
}
}
[Inline]
public static void ForEach<TList, TValue, TDlg>(this TList list, TDlg dlg)
where TList : concrete, IEnumerable<TValue>
where TDlg : delegate void(TValue)
{
for (let item in list)
dlg(item);
}
public class CTest
{
public int Test;
}
public static List<CTest> mList = new .() ~ delete _;
private static Event<EventHandler> mEvent;
[Test]
public static void TestBasics()
{
@ -144,6 +160,15 @@ namespace Tests
TestA ta = scope .();
ta.Vec = .(33, 44);
mList.Add(scope .());
mEvent.Add(new (sender, e) =>
{
mList.ForEach((b) => { b.Test = 1; });
});
mEvent(null, .Empty);
mEvent.Dispose();
Test.Assert(mList.Back.Test == 1);
}
struct MethodRefHolder<T> where T : delegate int(int num)