diff --git a/lib/std/core/array.c3 b/lib/std/core/array.c3 index 33d90236b..ab00fe671 100644 --- a/lib/std/core/array.c3 +++ b/lib/std/core/array.c3 @@ -55,7 +55,7 @@ macro rindex_of(array, element) * @require @typeis(arr1[0], $typeof(arr2[0])) "Arrays must have the same type" * @ensure result.len == arr1.len + arr2.len **/ -macro concat_new(arr1, arr2, Allocator allocator = allocator::heap()) +macro concat(arr1, arr2, Allocator allocator) @nodiscard { var $Type = $typeof(arr1[0]); $Type[] result = allocator::alloc_array(allocator, $Type, arr1.len + arr2.len); @@ -69,6 +69,21 @@ macro concat_new(arr1, arr2, Allocator allocator = allocator::heap()) } return result; } +/** + * Concatenate two arrays or slices, returning a slice containing the concatenation of them. + * + * @param [in] arr1 + * @param [in] arr2 + * @param [&inout] allocator "The allocator to use, default is the heap allocator" + * @require @typekind(arr1) == SLICE || @typekind(arr1) == ARRAY + * @require @typekind(arr2) == SLICE || @typekind(arr2) == ARRAY + * @require @typeis(arr1[0], $typeof(arr2[0])) "Arrays must have the same type" + * @ensure result.len == arr1.len + arr2.len + **/ +macro concat_new(arr1, arr2, Allocator allocator = allocator::heap()) @nodiscard +{ + return concat(arr1, arr2, allocator); +} /** * Concatenate two arrays or slices, returning a slice containing the concatenation of them, @@ -81,7 +96,7 @@ macro concat_new(arr1, arr2, Allocator allocator = allocator::heap()) * @require @typeis(arr1[0], $typeof(arr2[0])) "Arrays must have the same type" * @ensure result.len == arr1.len + arr2.len **/ -macro tconcat(arr1, arr2) => concat(arr1, arr2, allocator::temp()); +macro tconcat(arr1, arr2) @nodiscard => concat(arr1, arr2, allocator::temp()); module std::core::array::slice(); diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index f4068e4e0..d90568a9c 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1723,7 +1723,7 @@ SPLAT_NORMAL:; if (!sema_analyse_parameter(context, arg, params[i], callee->definition, optional, no_match_ref, callee->macro)) return false; actual_args[i] = arg; } - + if (num_args) last = args[num_args - 1]; call->call_expr.arguments = args; // 17. Set default values. for (unsigned i = 0; i < func_param_count; i++) diff --git a/test/unit/stdlib/core/array.c3 b/test/unit/stdlib/core/array.c3 index 58473c75c..6c11b4b19 100644 --- a/test/unit/stdlib/core/array.c3 +++ b/test/unit/stdlib/core/array.c3 @@ -21,11 +21,11 @@ fn void! find_subarray() fn void! concat() { int[3] a = { 1, 2, 3 }; - array::concat_new(a, a); - array::concat_new(a[..], a[..]); - array::concat_new(a[:0], a[:0]); - array::concat_new(int[2] { 1, 2 }, a[:0]); - array::concat_new(a[:0], int[2] { 1, 2 }); + (void)array::concat_new(a, a); + (void)array::concat_new(a[..], a[..]); + (void)array::concat_new(a[:0], a[:0]); + (void)array::concat_new(int[2] { 1, 2 }, a[:0]); + (void)array::concat_new(a[:0], int[2] { 1, 2 }); int[] c = array::concat_new(a[1..2], a); assert (c == int[]{ 2, 3, 1, 2, 3 }); }