Disallow slicing of constant values

This commit is contained in:
gingerBill
2021-05-15 16:40:40 +01:00
parent 63b54ce7c6
commit b01c2e1017
2 changed files with 28 additions and 4 deletions

View File

@@ -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++) {