- @if now does implicit conversion to bool like $if. #2086

This commit is contained in:
Christoffer Lerno
2025-04-16 23:49:12 +02:00
parent 6454856fdb
commit 3244898610
3 changed files with 13 additions and 1 deletions

View File

@@ -22,6 +22,7 @@
- Correctly detect multiple overloads of the same type.
- ABI bug on x64 Linux / MacOS when passing a union containing a struct of 3 floats. #2087
- Bug with slice acces as inline struct member #2088.
- `@if` now does implicit conversion to bool like `$if`. #2086
### Stdlib changes
- Hash functions for integer vectors and arrays.

View File

@@ -3126,7 +3126,7 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_
case ATTRIBUTE_IF:
if (!expr) RETURN_SEMA_ERROR(attr, "'@if' requires a boolean argument.");
if (!sema_analyse_expr(context, expr)) return false;
if (expr->type->canonical != type_bool || !sema_cast_const(expr))
if (!cast_explicit_silent(context, expr, type_bool) || !sema_cast_const(expr))
{
RETURN_SEMA_ERROR(expr, "Expected a boolean compile time constant value.");
}

View File

@@ -0,0 +1,11 @@
module test;
fn void main()
{
int $a = 0;
$if $a:
$endif;
int a @if(!$a);
int a @if($a);
int a @if((bool)$a);
}