mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
Fixed break targeting switch label
This commit is contained in:
parent
ac67046afc
commit
908a76b92a
3 changed files with 25 additions and 1 deletions
|
@ -1942,7 +1942,7 @@ void BfModule::NewScopeState(bool createLexicalBlock, bool flushValueScope)
|
||||||
{
|
{
|
||||||
if (checkScope->mLabel == mCurMethodState->mCurScope->mLabel)
|
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)
|
if (errorNode != NULL)
|
||||||
mCompiler->mPassInstance->MoreInfo("See previous scope label", checkScope->mLabelNode);
|
mCompiler->mPassInstance->MoreInfo("See previous scope label", checkScope->mLabelNode);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -5171,6 +5171,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
||||||
caseScopeData.mIsSharedTempBlock = true;
|
caseScopeData.mIsSharedTempBlock = true;
|
||||||
mCurMethodState->AddScope(&caseScopeData);
|
mCurMethodState->AddScope(&caseScopeData);
|
||||||
NewScopeState();
|
NewScopeState();
|
||||||
|
caseScopeData.mLabel = newScope.mLabel;
|
||||||
|
|
||||||
bool hadReturn = false;
|
bool hadReturn = false;
|
||||||
VisitCodeBlock(switchCase->mCodeBlock, BfIRBlock(), endBlock, BfIRBlock(), true, &hadReturn, switchStmt->mLabelNode);
|
VisitCodeBlock(switchCase->mCodeBlock, BfIRBlock(), endBlock, BfIRBlock(), true, &hadReturn, switchStmt->mLabelNode);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma warning disable 168
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Tests
|
namespace Tests
|
||||||
|
@ -42,6 +44,27 @@ namespace Tests
|
||||||
|
|
||||||
Shape shape = .Circle(10, 20, 30);
|
Shape shape = .Circle(10, 20, 30);
|
||||||
Test.Assert(Switch1(shape) == 12);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue