From 7853cb09ac6ad404f3151ce1a6129f343177c00b Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 28 Jul 2020 17:34:26 +0200 Subject: [PATCH] Added check when omitting end index for pointers. --- src/compiler/sema_expr.c | 5 +++++ test/test_suite/subarrays/slice_negative_len.c3 | 1 + 2 files changed, 6 insertions(+) diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index e5d4d5fcb..6b970c777 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -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."); diff --git a/test/test_suite/subarrays/slice_negative_len.c3 b/test/test_suite/subarrays/slice_negative_len.c3 index b1f9bc121..957feaa5c 100644 --- a/test/test_suite/subarrays/slice_negative_len.c3 +++ b/test/test_suite/subarrays/slice_negative_len.c3 @@ -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. } \ No newline at end of file