Correctly poison the analysis after a failed $assert or $error. #2284

This commit is contained in:
Christoffer Lerno
2025-07-09 16:51:43 +02:00
parent bf0ff8abbc
commit 299d1f530f
3 changed files with 8 additions and 1 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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
}