Skip to content

Commit

Permalink
Minor fix for the case where assert false (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankushdesai committed Feb 22, 2024
1 parent 5260881 commit 24f64b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Src/PCompiler/CompilerCore/Backend/IRTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ private List<IPStmt> SimplifyStatement(IPStmt statement)
case AssertStmt assertStmt:
(var assertExpr, var assertDeps) = SimplifyExpression(assertStmt.Assertion);
(var messageExpr, var messageDeps) = SimplifyExpression(assertStmt.Message);
if (assertExpr is BoolLiteralExpr)
{
return assertDeps.Concat(messageDeps).Concat(new []{new AssertStmt(location, assertExpr, messageExpr)}).ToList();
}

var ifStmtForAssert = new IfStmt(location, assertExpr, new NoStmt(location), new CompoundStmt(
location, messageDeps.Concat(new[]
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
machine Main {
start state Init {
entry {
var m: map[int, int];
assert !(1 in m), format("Yay! {0}", m[1]);
}
}
}

fun foo() : int {
if($)
return 0;

assert false, "A";
}

0 comments on commit 24f64b7

Please sign in to comment.