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

Allow enums with <=1 element (void underlying) cast to int (0)

This commit is contained in:
Brian Fiete 2024-11-19 09:04:34 -05:00
parent 9ca3fbd0dd
commit b12b49aec3

View file

@ -14611,6 +14611,13 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
auto fromTypedPrimitiveType = typedVal.mType->ToTypeInstance();
auto primTypedVal = BfTypedValue(typedVal.mValue, fromTypedPrimitiveType->mFieldInstances.back().mResolvedType, typedVal.IsAddr());
primTypedVal = LoadValue(primTypedVal);
if ((typedVal.mType->IsEnum()) && (primTypedVal.IsValuelessType()))
{
// For enums with <= 1 member, fake an int8(0) instead of a void
primTypedVal = GetDefaultTypedValue(GetPrimitiveType(BfTypeCode_Int8));
}
return CastToValue(srcNode, primTypedVal, toType, castFlags);
}