- Trying to slice an indexable type leads to misleading error message #2958

This commit is contained in:
Christoffer Lerno
2026-02-20 00:13:45 +01:00
parent 392c78860d
commit 0387d7666d
3 changed files with 10 additions and 1 deletions

View File

@@ -48,6 +48,7 @@
- On assert known false, the message was not show for no-args. - 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. - 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 - 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 ## 0.7.9 Change list

View File

@@ -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)) 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) if (current_expr != subscripted)
{ {

View File

@@ -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;
}