From bf30e52993e3a7b59884aa51fea06fb5e493c660 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 10 Oct 2024 14:59:16 +0200 Subject: [PATCH] Improved error message on invalid subscript index type #1535. --- releasenotes.md | 1 + src/compiler/sema_casts.c | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/releasenotes.md b/releasenotes.md index c613401bd..3fc734298 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -11,6 +11,7 @@ - Deprecate `@adhoc`, allow non-nested ad hoc generic types. - Constant bytes <=> char[] conversion should work #1514. - Infer now works across ternary. +- Improved error message on invalid subscript index type #1535. ### Fixes - `Unsupported int[*] $x = { 1, 2, 3, 4 }` #1489. diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index d451fdc3a..5d2ecc309 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -629,14 +629,8 @@ bool cast_to_index(SemaContext *context, Expr *index, Type *subscripted_type) type = type->decl->enums.type_info->type; goto RETRY; default: - if (!subscripted_type) - { - RETURN_SEMA_ERROR(index, "Cannot implicitly convert %s to an index.", - type_quoted_error_string(index->type)); - } - RETURN_SEMA_ERROR(index, "Cannot implicitly convert %s to index %s.", - type_quoted_error_string(index->type), - type_quoted_error_string(subscripted_type)); + RETURN_SEMA_ERROR(index, "An integer value was expected here, but it is a value of type %s, which can't be implicitly converted into an integer index.", + type_quoted_error_string(index->type)); } }