for &e, i in array and for k, &v in map (alternative to passing the iterable by pointer)

This commit is contained in:
gingerBill
2023-06-26 15:20:40 +01:00
parent 19ea090633
commit ea00619c3b
4 changed files with 94 additions and 39 deletions

View File

@@ -2273,7 +2273,15 @@ gb_internal void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast *
defer (end_error_block());
error(op, "Cannot take the pointer address of '%s'", str);
if (e != nullptr && (e->flags & EntityFlag_ForValue) != 0) {
error_line("\tSuggestion: Did you want to pass the iterable value to the for statement by pointer to get addressable semantics?\n");
Type *parent_type = type_deref(e->Variable.for_loop_parent_type);
if (parent_type != nullptr && is_type_string(parent_type)) {
error_line("\tSuggestion: Iterating over a string produces an intermediate 'rune' value which cannot be addressed.\n");
} else if (parent_type != nullptr && is_type_tuple(parent_type)) {
error_line("\tSuggestion: Iterating over a procedure does not produce values which are addressable.\n");
} else {
error_line("\tSuggestion: Did you want to pass the iterable value to the for statement by pointer to get addressable semantics?\n");
}
}
if (e != nullptr && (e->flags & EntityFlag_SwitchValue) != 0) {
error_line("\tSuggestion: Did you want to pass the value to the switch statement by pointer to get addressable semantics?\n");