From 908a76b92a6422585e74644e2d0668b37ae83ab3 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 20 Nov 2024 11:33:28 -0500 Subject: [PATCH] Fixed break targeting switch label --- IDEHelper/Compiler/BfModule.cpp | 2 +- IDEHelper/Compiler/BfStmtEvaluator.cpp | 1 + IDEHelper/Tests/src/Switches.bf | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index df45c1fe..d52ea990 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -1942,7 +1942,7 @@ void BfModule::NewScopeState(bool createLexicalBlock, bool flushValueScope) { if (checkScope->mLabel == mCurMethodState->mCurScope->mLabel) { - auto errorNode = Fail("Duplicate scope label", curScope->mLabelNode); + auto errorNode = Warn(0, StrFormat("Duplicate scope label '%s'", checkScope->mLabel.c_str()), curScope->mLabelNode); if (errorNode != NULL) mCompiler->mPassInstance->MoreInfo("See previous scope label", checkScope->mLabelNode); break; diff --git a/IDEHelper/Compiler/BfStmtEvaluator.cpp b/IDEHelper/Compiler/BfStmtEvaluator.cpp index 21d20729..f5c23244 100644 --- a/IDEHelper/Compiler/BfStmtEvaluator.cpp +++ b/IDEHelper/Compiler/BfStmtEvaluator.cpp @@ -5171,6 +5171,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) caseScopeData.mIsSharedTempBlock = true; mCurMethodState->AddScope(&caseScopeData); NewScopeState(); + caseScopeData.mLabel = newScope.mLabel; bool hadReturn = false; VisitCodeBlock(switchCase->mCodeBlock, BfIRBlock(), endBlock, BfIRBlock(), true, &hadReturn, switchStmt->mLabelNode); diff --git a/IDEHelper/Tests/src/Switches.bf b/IDEHelper/Tests/src/Switches.bf index 6ebf049d..22d101fc 100644 --- a/IDEHelper/Tests/src/Switches.bf +++ b/IDEHelper/Tests/src/Switches.bf @@ -1,3 +1,5 @@ +#pragma warning disable 168 + using System; namespace Tests @@ -42,6 +44,27 @@ namespace Tests Shape shape = .Circle(10, 20, 30); Test.Assert(Switch1(shape) == 12); + + int val = 123; + int result = 0; + switch (val) + { + case 0: + result = 1; + default: + SWITCH2: + switch (val) + { + case 2: + result = 2; + default: + result = 3; + break SWITCH2; + } + + result = 4; + } + Test.Assert(result == 4); } } }