diff --git a/releasenotes.md b/releasenotes.md index da50ea91a..b4804be15 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -40,6 +40,7 @@ - Fix to codegen when using a bitstruct constant defined using a cast with an operator #2248. - Function pointers are now compile time constants. - Splat 8 arguments can sometimes cause incorrect behaviour in the compiler. #2283 +- Correctly poison the analysis after a failed $assert or $error. #2284 ### Stdlib changes - Improve contract for readline. #2280 diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index 8d512ff48..785bacd24 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -2930,7 +2930,7 @@ bool sema_analyse_ct_assert_stmt(SemaContext *context, Ast *statement) if (!sema_analyse_expr(context, message_expr)) return false; if (message_expr->expr_kind != EXPR_CONST || message_expr->const_expr.const_kind != CONST_STRING) { - SEMA_ERROR(message_expr, "Expected a string as the error message."); + RETURN_SEMA_ERROR(message_expr, "Expected a string as the error message."); } } CondResult res = expr ? sema_check_comp_time_bool(context, expr) : COND_FALSE; @@ -2949,6 +2949,7 @@ bool sema_analyse_ct_assert_stmt(SemaContext *context, Ast *statement) { sema_error_at(context, span, "Compile time assert failed."); } + context->active_scope.is_poisoned = true; return false; } statement->ast_kind = AST_NOP_STMT; diff --git a/test/test_suite/assert/format_ct_assert.c3 b/test/test_suite/assert/format_ct_assert.c3 index 907661cea..781ee249b 100644 --- a/test/test_suite/assert/format_ct_assert.c3 +++ b/test/test_suite/assert/format_ct_assert.c3 @@ -1,5 +1,10 @@ fn void main() { $error "Foo %s", 1; // #error: Foo 1 + $assert 0 > 1 : "Foo %s", 0.0002; +} + +fn void test() +{ $assert 0 > 1 : "Foo %s", 0.0002; // #error: Foo 0.0002 }