From 2d76efdaaaaf4776ccd1bdd4d68d435bd193a80a Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 17 Feb 2021 07:37:37 -0800 Subject: [PATCH] Require explicit cast for enum-constrained generic-to-int conversion --- IDEHelper/Compiler/BfModuleTypeUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 3b6a7b4e..cb4e4863 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -11079,7 +11079,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp { SetAndRestoreValue 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) {