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:
parent
5a3701fa90
commit
044f15629d
1 changed files with 9 additions and 2 deletions
|
@ -9568,7 +9568,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
if ((constraintTypeInst != NULL) && (constraintTypeInst->mTypeDef == mCompiler->mEnumTypeDef))
|
if ((constraintTypeInst != NULL) && (constraintTypeInst->mTypeDef == mCompiler->mEnumTypeDef))
|
||||||
{
|
{
|
||||||
// Enum->int
|
// Enum->int
|
||||||
if (toType->IsInteger())
|
if ((explicitCast) && (toType->IsInteger()))
|
||||||
return GetDefaultValue(toType);
|
return GetDefaultValue(toType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9657,7 +9657,14 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
}
|
}
|
||||||
|
|
||||||
if (genericParamInst->mTypeConstraint != NULL)
|
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));
|
auto castedVal = CastToValue(srcNode, typedVal, genericParamInst->mTypeConstraint, (BfCastFlags)(castFlags | BfCastFlags_SilentFail));
|
||||||
if (castedVal)
|
if (castedVal)
|
||||||
return castedVal;
|
return castedVal;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue