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

Fixed crash when using a failed closure

This commit is contained in:
Brian Fiete 2020-02-28 11:12:21 -08:00
parent c92bc523db
commit bb34a468bb
4 changed files with 9 additions and 5 deletions

View file

@ -389,6 +389,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly)
mDbgRawAllocDataTypeDef = NULL;
mDeferredCallTypeDef = NULL;
mDelegateTypeDef = NULL;
mActionTypeDef = NULL;
mEnumTypeDef = NULL;
mFriendAttributeTypeDef = NULL;
mCheckedAttributeTypeDef = NULL;
@ -5916,6 +5917,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
mDbgRawAllocDataTypeDef = _GetRequiredType("System.DbgRawAllocData");
mDeferredCallTypeDef = _GetRequiredType("System.DeferredCall");
mDelegateTypeDef = _GetRequiredType("System.Delegate");
mActionTypeDef = _GetRequiredType("System.Action");
mEnumTypeDef = _GetRequiredType("System.Enum");
mFriendAttributeTypeDef = _GetRequiredType("System.FriendAttribute");
mCheckedAttributeTypeDef = _GetRequiredType("System.CheckedAttribute");

View file

@ -338,8 +338,9 @@ public:
BfTypeDef* mClassVDataTypeDef;
BfTypeDef* mDbgRawAllocDataTypeDef;
BfTypeDef* mDeferredCallTypeDef;
BfTypeDef* mDeferredCallTypeDef;
BfTypeDef* mDelegateTypeDef;
BfTypeDef* mActionTypeDef;
BfTypeDef* mEnumTypeDef;
BfTypeDef* mStringTypeDef;
BfTypeDef* mTypeTypeDef;

View file

@ -464,7 +464,7 @@ bool BfMethodMatcher::InferGenericArgument(BfMethodInstance* methodInstance, BfT
auto argInvokeMethod = mModule->GetRawMethodByName(argType->ToTypeInstance(), "Invoke");
auto wantInvokeMethod = mModule->GetRawMethodByName(wantType->ToTypeInstance(), "Invoke");
if (argInvokeMethod->GetParamCount() == wantInvokeMethod->GetParamCount())
if ((argInvokeMethod != NULL) && (wantInvokeMethod != NULL) && (argInvokeMethod->GetParamCount() == wantInvokeMethod->GetParamCount()))
{
InferGenericArgument(methodInstance, argInvokeMethod->mReturnType, wantInvokeMethod->mReturnType, BfIRValue(), checkedTypeSet);
for (int argIdx = 0; argIdx < (int)argInvokeMethod->GetParamCount(); argIdx++)
@ -9604,13 +9604,13 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
sBindCount++;
bool isFunctionBind = false;
BfTypeInstance* delegateTypeInstance = NULL;
BfMethodInstance* invokeMethodInstance = NULL;
if (mExpectingType == NULL)
{
mModule->Fail("Cannot infer delegate type", lambdaBindExpr);
delegateTypeInstance = mModule->mContext->mBfObjectType;
delegateTypeInstance = mModule->ResolveTypeDef(mModule->mCompiler->mActionTypeDef)->ToTypeInstance();
}
else
{
@ -9620,7 +9620,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
{
if (lambdaBindExpr->mFatArrowToken != NULL)
mModule->Fail("Can only bind lambdas to delegate types", lambdaBindExpr->mFatArrowToken);
delegateTypeInstance = mModule->mContext->mBfObjectType;
delegateTypeInstance = mModule->ResolveTypeDef(mModule->mCompiler->mActionTypeDef)->ToTypeInstance();
}
else
{

View file

@ -1760,6 +1760,7 @@ void BfTypeInstance::CalcHotVirtualData(Array<int>* ifaceMapping)
BfClosureType::BfClosureType(BfTypeInstance* srcDelegate, Val128 closureHash) :
mSource(srcDelegate->mTypeDef->mSystem)
{
BF_ASSERT(srcDelegate->IsDelegate());
mSrcDelegate = srcDelegate;
mTypeDef = mSrcDelegate->mTypeDef;
mCreatedTypeDef = false;