mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-11 04:52:21 +02:00
Fixed 'when' on switch payload case
This commit is contained in:
parent
864d5e9d24
commit
d36d076e95
2 changed files with 34 additions and 1 deletions
|
@ -4950,6 +4950,10 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
|
||||||
mBfIRBuilder->SetInsertPoint(notEqBB);
|
mBfIRBuilder->SetInsertPoint(notEqBB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (whenExpr != NULL)
|
||||||
|
{
|
||||||
|
mayHaveMatch = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (notEqBB)
|
if (notEqBB)
|
||||||
lastNotEqBlock = notEqBB;
|
lastNotEqBlock = notEqBB;
|
||||||
|
|
|
@ -4,7 +4,13 @@ namespace Tests
|
||||||
{
|
{
|
||||||
class Switches
|
class Switches
|
||||||
{
|
{
|
||||||
int Switch0(Result<int> res)
|
enum Shape
|
||||||
|
{
|
||||||
|
case Rectangle(int x, int y, int width, int height);
|
||||||
|
case Circle(int x, int y, int radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Switch0(Result<int> res)
|
||||||
{
|
{
|
||||||
switch (res)
|
switch (res)
|
||||||
{
|
{
|
||||||
|
@ -14,5 +20,28 @@ namespace Tests
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int Switch1(Shape shape)
|
||||||
|
{
|
||||||
|
switch (shape)
|
||||||
|
{
|
||||||
|
case .Circle(let x, let y, let radius) when x > 0 && y == 10:
|
||||||
|
return 12;
|
||||||
|
default:
|
||||||
|
return 23;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public static void TestBasics()
|
||||||
|
{
|
||||||
|
Result<int> val0 = .Ok(1);
|
||||||
|
Test.Assert(Switch0(val0) == 0);
|
||||||
|
val0 = .Err;
|
||||||
|
Test.Assert(Switch0(val0) == 1);
|
||||||
|
|
||||||
|
Shape shape = .Circle(10, 20, 30);
|
||||||
|
Test.Assert(Switch1(shape) == 12);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue