mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Fixed type conversion for enumerators in for-each loops
This commit is contained in:
parent
13ca5c174d
commit
fc57557fd9
1 changed files with 16 additions and 4 deletions
|
@ -5874,6 +5874,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt)
|
||||||
|
|
||||||
BfModuleMethodInstance getNextMethodInst;
|
BfModuleMethodInstance getNextMethodInst;
|
||||||
|
|
||||||
|
BfType* nextEmbeddedType = NULL;
|
||||||
BfTypedValue nextResult;
|
BfTypedValue nextResult;
|
||||||
if ((refItrInterface) || (itrInterface))
|
if ((refItrInterface) || (itrInterface))
|
||||||
{
|
{
|
||||||
|
@ -5889,7 +5890,14 @@ void BfModule::Visit(BfForEachStatement* forEachStmt)
|
||||||
}
|
}
|
||||||
BF_ASSERT(getNextMethodInst);
|
BF_ASSERT(getNextMethodInst);
|
||||||
nextResult = BfTypedValue(CreateAlloca(getNextMethodInst.mMethodInstance->mReturnType), getNextMethodInst.mMethodInstance->mReturnType, true);
|
nextResult = BfTypedValue(CreateAlloca(getNextMethodInst.mMethodInstance->mReturnType), getNextMethodInst.mMethodInstance->mReturnType, true);
|
||||||
|
|
||||||
|
if (nextResult.mType->IsGenericTypeInstance())
|
||||||
|
{
|
||||||
|
nextEmbeddedType = ((BfGenericTypeInstance*)nextResult.mType)->mTypeGenericArguments[0];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (nextEmbeddedType == NULL)
|
||||||
|
nextEmbeddedType = mContext->mBfObjectType;
|
||||||
|
|
||||||
BfLocalVariable* itrLocalDef = NULL;
|
BfLocalVariable* itrLocalDef = NULL;
|
||||||
|
|
||||||
|
@ -6234,9 +6242,13 @@ void BfModule::Visit(BfForEachStatement* forEachStmt)
|
||||||
{
|
{
|
||||||
if (needsValCopy)
|
if (needsValCopy)
|
||||||
{
|
{
|
||||||
auto valAddr = mBfIRBuilder->CreateBitCast(nextResult.mValue, mBfIRBuilder->MapType(CreatePointerType(varType)));
|
auto nextVal = BfTypedValue(mBfIRBuilder->CreateBitCast(nextResult.mValue, mBfIRBuilder->MapType(CreatePointerType(nextEmbeddedType))), nextEmbeddedType, true);
|
||||||
auto val = mBfIRBuilder->CreateLoad(valAddr);
|
if (isRefExpression)
|
||||||
mBfIRBuilder->CreateStore(val, varInst);
|
nextVal = BfTypedValue(nextVal.mValue, CreateRefType(nextVal.mType->GetUnderlyingType()), true);
|
||||||
|
nextVal = Cast(forEachStmt->mCollectionExpression, nextVal, varType, BfCastFlags_Explicit);
|
||||||
|
nextVal = LoadValue(nextVal);
|
||||||
|
if (nextVal)
|
||||||
|
mBfIRBuilder->CreateStore(nextVal.mValue, varInst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue