From 425676a98d6524d5502fffdd87bbb019872d8fe2 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sun, 16 Mar 2025 10:58:13 +0100 Subject: [PATCH] Bug due to missing cast when doing `$i[$x] = $z`. Added `math::iota`. --- lib/std/core/mem.c3 | 2 +- lib/std/math/math.c3 | 12 ++++++++++++ releasenotes.md | 2 ++ src/compiler/sema_expr.c | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/std/core/mem.c3 b/lib/std/core/mem.c3 index 7ff3de886..3c1ac07f5 100644 --- a/lib/std/core/mem.c3 +++ b/lib/std/core/mem.c3 @@ -633,7 +633,7 @@ module std::core::mem; macro TrackingEnv* get_tracking_env() { $if env::TRACK_MEMORY: - return &&TrackingEnv { $$FILE, $$FUNC, $$LINE }; + return &&(TrackingEnv){ $$FILE, $$FUNC, $$LINE }; $else return null; $endif diff --git a/lib/std/math/math.c3 b/lib/std/math/math.c3 index 71343cf5f..ee170921a 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -1145,6 +1145,18 @@ macro overflow_mul_helper(x, y) @local return res; } +<* + @require types::is_vector($Type) || ($Type.kindof == ARRAY &&& types::is_numerical($typefrom($Type.inner))) +*> +macro iota($Type) +{ + $Type $val = {}; + $for var $i = 0; $i < $Type.len; $i++: + $val[$i] = $i; + $endfor + return $val; +} + macro mul_div_helper(val, mul, div) @private { var $Type = $typeof(val); diff --git a/releasenotes.md b/releasenotes.md index 0d146d14f..48ce621a1 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -47,6 +47,7 @@ - `import` can now both be @public and @norecurse. - Crash when trying to convert a struct slice to a vector #2039. - Crash resolving a method on `Foo[2]` when `Foo` is distinct #2042. +- Bug due to missing cast when doing `$i[$x] = $z`. ### Stdlib changes - `new_*` functions in general moved to version without `new_` prefix. @@ -61,6 +62,7 @@ - Change all hash functions to have a common `hash` function. - `@wstring`, `@wstring32`, `@char32` and `@char16` compile time macros added. - Updates to `Atomic` to handle distinct types and booleans. +- Added `math::iota`. ## 0.6.8 Change list diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 661c49e55..86049ed44 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -5745,7 +5745,7 @@ static bool sema_expr_analyse_ct_subscript_rhs(SemaContext *context, Decl *ct_va } else { - if (!sema_analyse_inferred_expr(context, type_get_indexed_type(ct_var->type), right)) return false; + if (!sema_analyse_expr_rhs(context, type_get_indexed_type(ct_var->type), right, false, NULL, false)) return false; } if (!sema_cast_const(right)) {