Added check when omitting end index for pointers.

This commit is contained in:
Christoffer Lerno
2020-07-28 17:34:26 +02:00
committed by Christoffer Lerno
parent ce68bda86c
commit 7853cb09ac
2 changed files with 6 additions and 0 deletions

View File

@@ -852,6 +852,11 @@ static inline bool sema_expr_analyse_slice_after_parent_resolution(Context *cont
SEMA_ERROR(expr->slice_expr.start, "Indexing from the end is not allowed for pointers.");
return false;
}
if (!end)
{
SEMA_ERROR(expr, "Omitting end index is not allowed for pointers.");
return false;
}
if (end && expr->slice_expr.end_from_back)
{
SEMA_ERROR(expr->slice_expr.end, "Indexing from the end is not allowed for pointers.");

View File

@@ -60,6 +60,7 @@ func void test10()
{
int* x = nil;
x[-10..-3];
int[] w = x[0..]; // #error: Omitting end index is not allowed for pointers.
int[] z = x[^2..]; // #error: Indexing from the end is not allowed for pointers.
int[] y = x[..^2]; // #error: Indexing from the end is not allowed for pointers.
}