From 24f64b78677a4643bbcb4a9ae625d4daac0758fa Mon Sep 17 00:00:00 2001 From: Ankush Desai Date: Wed, 21 Feb 2024 20:59:30 -0800 Subject: [PATCH] Minor fix for the case where `assert false` (#697) --- .../CompilerCore/Backend/IRTransformer.cs | 5 +++++ .../Correct/assertMessage2/assertMessage2.p | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 Tst/RegressionTests/Feature3Exprs/Correct/assertMessage2/assertMessage2.p diff --git a/Src/PCompiler/CompilerCore/Backend/IRTransformer.cs b/Src/PCompiler/CompilerCore/Backend/IRTransformer.cs index 6c98c12027..5afe0fc8f6 100644 --- a/Src/PCompiler/CompilerCore/Backend/IRTransformer.cs +++ b/Src/PCompiler/CompilerCore/Backend/IRTransformer.cs @@ -352,6 +352,11 @@ private List 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[] { diff --git a/Tst/RegressionTests/Feature3Exprs/Correct/assertMessage2/assertMessage2.p b/Tst/RegressionTests/Feature3Exprs/Correct/assertMessage2/assertMessage2.p new file mode 100644 index 0000000000..a153b06cea --- /dev/null +++ b/Tst/RegressionTests/Feature3Exprs/Correct/assertMessage2/assertMessage2.p @@ -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"; +}