Skip to content

Commit e7634dd

Browse files
authored
Fixes the early evaluation problem with assert statements in P (#695)
1 parent 0a56679 commit e7634dd

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Src/PCompiler/CompilerCore/Backend/IRTransformer.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,12 @@ 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-
356-
return assertDeps.Concat(messageDeps).Concat(new[]
355+
var ifStmtForAssert = new IfStmt(location, assertExpr, new NoStmt(location), new CompoundStmt(
356+
location, messageDeps.Concat(new[]
357357
{
358358
new AssertStmt(location, assertExpr, messageExpr)
359-
})
359+
}).ToList()));
360+
return assertDeps.Concat(new List<IPStmt>{ifStmtForAssert})
360361
.ToList();
361362

362363
case AssignStmt assignStmt:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}

0 commit comments

Comments
 (0)