Designated initialization with ranges would not error on overflow by 1.

This commit is contained in:
Christoffer Lerno
2026-01-03 02:32:40 +01:00
parent 82769669ec
commit 292bf1cbbc
3 changed files with 19 additions and 2 deletions

View File

@@ -48,6 +48,7 @@
- `String.tokenize_all` would yield one too many empty tokens at the end.
- `String.replace` no longer depends on `String.split`.
- Fix the case where `\u<unicode char>` could crash the compiler on some platforms.
- Designated initialization with ranges would not error on overflow by 1.
### Stdlib changes
- Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads.

View File

@@ -1377,10 +1377,10 @@ static Type *sema_find_type_of_element(SemaContext *context, Type *type, Designa
*did_report_error = true;
return NULL;
}
if (end_index > (ArrayIndex)len)
if (end_index >= (ArrayIndex)len)
{
*did_report_error = true;
SEMA_ERROR(element->index_expr, "The index may must be less than the array length (which was %llu).", (unsigned long long)len);
SEMA_ERROR(element->index_end_expr, "The index must be less than the array length (which was %llu).", (unsigned long long)len);
return NULL;
}
element->index_end = end_index;

View File

@@ -0,0 +1,16 @@
enum Row : inline int { A, B, C, D, E, F }
int[3][6] m = {
[Row.E] = {
[0..3] = 1, // #error: The index must be less than the array length (which was 3)
},
[Row.F] = {
[1] = 2,
},
};
fn int main()
{
(void)m;
return 0;
}