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

Added ability to explicitly cast from int to enum generic constraint

This commit is contained in:
Brian Fiete 2020-08-16 15:56:59 -07:00
parent 5a3701fa90
commit 044f15629d

View file

@ -9568,7 +9568,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
if ((constraintTypeInst != NULL) && (constraintTypeInst->mTypeDef == mCompiler->mEnumTypeDef))
{
// Enum->int
if (toType->IsInteger())
if ((explicitCast) && (toType->IsInteger()))
return GetDefaultValue(toType);
}
@ -9658,6 +9658,13 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
if (genericParamInst->mTypeConstraint != NULL)
{
if (genericParamInst->mTypeConstraint->IsInstanceOf(mCompiler->mEnumTypeDef))
{
// int->Enum
if ((explicitCast) && (typedVal.mType->IsInteger()))
return mBfIRBuilder->GetFakeVal();
}
auto castedVal = CastToValue(srcNode, typedVal, genericParamInst->mTypeConstraint, (BfCastFlags)(castFlags | BfCastFlags_SilentFail));
if (castedVal)
return castedVal;