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

Fixed result-of-tuple crash

This commit is contained in:
Brian Fiete 2020-06-19 06:40:40 -07:00
parent 3863166545
commit 407c742bf9
2 changed files with 19 additions and 8 deletions

View file

@ -6428,8 +6428,7 @@ BfTypedValue BfExprEvaluator::CheckEnumCreation(BfAstNode* targetSrc, BfTypeInst
if (argValue)
{
// argValue can have a value even if tuplePtr does not have a value. This can happen if we are assigning to a (void) tuple,
// but we have a value that needs to be attempted to be casted to void
// but we have a value that needs to be attempted to be casted to void
argValue = mModule->Cast(argValues.mResolvedArgs[tupleFieldIdx].mExpression, argValue, resolvedFieldType);
if (tupleFieldPtr)
{
@ -11415,11 +11414,14 @@ void BfExprEvaluator::Visit(BfLambdaBindExpression* lambdaBindExpr)
break;
}
capturedValue = capturedTypedVal.mValue;
if (capturedValue)
{
auto fieldPtr = mModule->mBfIRBuilder->CreateInBoundsGEP(mResult.mValue, 0, fieldInstance->mDataIdx);
mModule->mBfIRBuilder->CreateStore(capturedValue, fieldPtr);
if (!capturedTypedVal.mType->IsVar())
{
auto fieldPtr = mModule->mBfIRBuilder->CreateInBoundsGEP(mResult.mValue, 0, fieldInstance->mDataIdx);
mModule->mBfIRBuilder->CreateStore(capturedValue, fieldPtr);
}
}
else
{
@ -14638,9 +14640,17 @@ BfModuleMethodInstance BfExprEvaluator::GetPropertyMethodInstance(BfMethodDef* m
auto propTypeInst = mPropTarget.mType->ToTypeInstance();
auto rawMethodInstance = mModule->GetRawMethodInstance(propTypeInst, methodDef);
auto useTypeInst = mOrigPropTarget.mType->ToTypeInstance();
auto virtualMethod = (BfMethodInstance*)useTypeInst->mVirtualMethodTable[rawMethodInstance->mVirtualTableIdx].mImplementingMethod;
return mModule->ReferenceExternalMethodInstance(virtualMethod);
BF_ASSERT(rawMethodInstance->mVirtualTableIdx != -1);
if (rawMethodInstance->mVirtualTableIdx == -1)
{
mModule->Fail(StrFormat("Failed to devirtualize %s", mModule->MethodToString(rawMethodInstance).c_str()));
}
else
{
auto useTypeInst = mOrigPropTarget.mType->ToTypeInstance();
auto virtualMethod = (BfMethodInstance*)useTypeInst->mVirtualMethodTable[rawMethodInstance->mVirtualTableIdx].mImplementingMethod;
return mModule->ReferenceExternalMethodInstance(virtualMethod);
}
}
}

View file

@ -10224,6 +10224,7 @@ BfTypedValue BfModule::Cast(BfAstNode* srcNode, const BfTypedValue& typedVal, Bf
if (!castedElementVal)
return BfTypedValue();
auto fieldRef = mBfIRBuilder->CreateInBoundsGEP(curTupleValue, 0, toFieldInstance->mDataIdx);
castedElementVal = LoadValue(castedElementVal);
mBfIRBuilder->CreateStore(castedElementVal.mValue, fieldRef);
}
else