Skip to content

Commit

Permalink
Improved error message on invalid subscript index type #1535.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Oct 10, 2024
1 parent a91ddd4 commit bf30e52
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 2 additions & 8 deletions src/compiler/sema_casts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down

0 comments on commit bf30e52

Please sign in to comment.