mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Fixed struct ref casts
This commit is contained in:
parent
e3cceff39c
commit
487787b08e
1 changed files with 15 additions and 1 deletions
|
@ -12597,9 +12597,11 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
// Ref X to Ref Y, X* to Y*
|
||||
{
|
||||
bool checkUnderlying = false;
|
||||
bool isRef = false;
|
||||
|
||||
if (((typedVal.mType->IsRef()) && (toType->IsRef())))
|
||||
{
|
||||
isRef = true;
|
||||
auto fromRefType = (BfRefType*)typedVal.mType;
|
||||
auto toRefType = (BfRefType*)toType;
|
||||
if (fromRefType->mRefKind == toRefType->mRefKind)
|
||||
|
@ -12639,12 +12641,24 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
if (matches)
|
||||
{
|
||||
// This is either a ref or a ptr so we don't need to set the "IsAddr" flag
|
||||
typedVal = MakeAddressable(typedVal);
|
||||
typedVal = MakeAddressable(typedVal);
|
||||
return mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapType(toType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((isRef) && (fromInner->IsStruct()) && (toInner->IsStruct()))
|
||||
{
|
||||
if (TypeIsSubTypeOf(fromInner->ToTypeInstance(), toInner->ToTypeInstance()))
|
||||
{
|
||||
if (toInner->IsValuelessType())
|
||||
return mBfIRBuilder->GetFakeVal();
|
||||
// Is this valid?
|
||||
typedVal = MakeAddressable(typedVal);
|
||||
return mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapType(toType));
|
||||
}
|
||||
}
|
||||
|
||||
// ref int <-> ref int64/int32 (of same size)
|
||||
if (((fromInner->IsInteger()) && (toInner->IsInteger())) &&
|
||||
(fromInner->mSize == toInner->mSize) &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue