From 7c292a8814cf37afbc391a349313c35990a71a2d Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 27 Nov 2021 11:11:41 -0800 Subject: [PATCH] Fixed scope for switch with tuple member captures --- IDEHelper/Compiler/BfStmtEvaluator.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/IDEHelper/Compiler/BfStmtEvaluator.cpp b/IDEHelper/Compiler/BfStmtEvaluator.cpp index e2a8a117..a3bda91d 100644 --- a/IDEHelper/Compiler/BfStmtEvaluator.cpp +++ b/IDEHelper/Compiler/BfStmtEvaluator.cpp @@ -4343,6 +4343,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) mBfIRBuilder->SetInsertPoint(noSwitchBlock); bool isPayloadEnum = switchValue.mType->IsPayloadEnum(); + bool isTuple = switchValue.mType->IsTuple(); bool isIntegralSwitch = switchValue.mType->IsIntegral() || (intCoercibleType != NULL) || ((switchValue.mType->IsEnum()) && (!isPayloadEnum)); auto _ShowCaseError = [&] (int64 id, BfAstNode* errNode) @@ -4433,6 +4434,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) } } + bool wantsOpenedScope = isPayloadEnum || isTuple; + BfIRBlock lastNotEqBlock; for (BfExpression* caseExpr : switchCase->mCaseExpressions) { @@ -4441,7 +4444,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) if (auto checkWhenExpr = BfNodeDynCast(caseExpr)) continue; - if ((!openedScope) && (isPayloadEnum)) + if ((!openedScope) && (wantsOpenedScope)) { openedScope = true;