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