Skip to content

Commit 24f64b7

Browse files
authored
Minor fix for the case where assert false (#697)
1 parent 5260881 commit 24f64b7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Src/PCompiler/CompilerCore/Backend/IRTransformer.cs

+5
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@ private List<IPStmt> SimplifyStatement(IPStmt statement)
352352
case AssertStmt assertStmt:
353353
(var assertExpr, var assertDeps) = SimplifyExpression(assertStmt.Assertion);
354354
(var messageExpr, var messageDeps) = SimplifyExpression(assertStmt.Message);
355+
if (assertExpr is BoolLiteralExpr)
356+
{
357+
return assertDeps.Concat(messageDeps).Concat(new []{new AssertStmt(location, assertExpr, messageExpr)}).ToList();
358+
}
359+
355360
var ifStmtForAssert = new IfStmt(location, assertExpr, new NoStmt(location), new CompoundStmt(
356361
location, messageDeps.Concat(new[]
357362
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
machine Main {
2+
start state Init {
3+
entry {
4+
var m: map[int, int];
5+
assert !(1 in m), format("Yay! {0}", m[1]);
6+
}
7+
}
8+
}
9+
10+
fun foo() : int {
11+
if($)
12+
return 0;
13+
14+
assert false, "A";
15+
}

0 commit comments

Comments
 (0)