From 0387d7666dfb8aaa138c620b2e9bd144d4488d35 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 20 Feb 2026 00:13:45 +0100 Subject: [PATCH] - Trying to slice an indexable type leads to misleading error message #2958 --- releasenotes.md | 1 + src/compiler/sema_expr.c | 2 +- test/test_suite/arrays/slice_no_overload.c3 | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/test_suite/arrays/slice_no_overload.c3 diff --git a/releasenotes.md b/releasenotes.md index b6cd443af..395eb0f65 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -48,6 +48,7 @@ - On assert known false, the message was not show for no-args. - Adding the incorrect sized vector to a pointer vector would cause a crash. - Member access on a struct returned by the assignment expression, cause crash #2947 +- Trying to slice an indexable type leads to misleading error message #2958 ## 0.7.9 Change list diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 62ab4f8cc..7108a8738 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -4848,7 +4848,7 @@ static inline bool sema_expr_analyse_slice(SemaContext *context, Expr *expr) if (!inner_type || !type_is_valid_for_array(inner_type)) { - RETURN_SEMA_ERROR(subscripted, "Cannot index %s.", type_quoted_error_string(subscripted->type)); + RETURN_SEMA_ERROR(subscripted, "You cannot slice %s.", type_quoted_error_string(subscripted->type)); } if (current_expr != subscripted) { diff --git a/test/test_suite/arrays/slice_no_overload.c3 b/test/test_suite/arrays/slice_no_overload.c3 new file mode 100644 index 000000000..e5a5fb599 --- /dev/null +++ b/test/test_suite/arrays/slice_no_overload.c3 @@ -0,0 +1,8 @@ +import std; + +fn int main() +{ + List {int} int_list; + int[] int_slice = int_list[..]; // #error: You cannot slice 'List{int}' + return 0; +} \ No newline at end of file