aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-05-15 16:40:40 +0100
committergingerBill <bill@gingerbill.org>2021-05-15 16:40:40 +0100
commitb01c2e101712cf58e60bfc41d85fc33b60fcf349 (patch)
tree4eac823f639370f2a1dd229a3eb9e7ea5b72ba65 /src/check_expr.cpp
parent63b54ce7c695fb1e204fe77db029cdebf7206b28 (diff)
Disallow slicing of constant values
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 51dad8f79..18f210b63 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -7811,10 +7811,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
return kind;
}
- o->mode = Addressing_Value;
-
if (se->low == nullptr && se->high != nullptr) {
- // error(se->interval0, "1st index is required if a 2nd index is specified");
// It is okay to continue as it will assume the 1st index is zero
}
@@ -7849,6 +7846,16 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
}
}
+ if (max_count < 0) {
+ if (o->mode == Addressing_Constant) {
+ gbString s = expr_to_string(se->expr);
+ error(se->expr, "Cannot slice constant value '%s'", s);
+ gb_string_free(s);
+ }
+ }
+
+ o->mode = Addressing_Value;
+
if (is_type_string(t) && max_count >= 0) {
bool all_constant = true;
for (isize i = 0; i < gb_count_of(nodes); i++) {