1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-14 14:24:10 +02:00

Require explicit cast for enum-constrained generic-to-int conversion

This commit is contained in:
Brian Fiete 2021-02-17 07:37:37 -08:00
parent d460c1fb2f
commit 2d76efdaaa

View file

@ -11079,7 +11079,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
{
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true);
auto constraintTypeInst = genericParamInst->mTypeConstraint->ToTypeInstance();
if ((constraintTypeInst != NULL) && (constraintTypeInst->mTypeDef == mCompiler->mEnumTypeDef))
if ((constraintTypeInst != NULL) && (constraintTypeInst->mTypeDef == mCompiler->mEnumTypeDef) && (explicitCast))
{
// Enum->int
if ((explicitCast) && (toType->IsInteger()))
@ -11118,7 +11118,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
}
}
if (toType->IsInteger())
if ((toType->IsInteger()) && (explicitCast))
{
if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Enum) != 0)
{