mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- @if now does implicit conversion to bool like $if. #2086
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
11
test/test_suite/compile_time/ct_if_bool_conversion_2086.c3
Normal file
11
test/test_suite/compile_time/ct_if_bool_conversion_2086.c3
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user