aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-06-26 15:20:40 +0100
committergingerBill <bill@gingerbill.org>2023-06-26 15:20:40 +0100
commitea00619c3bc1baacd249552397c445fd86dd7500 (patch)
tree3f8c6512719af53e766b610d0205b56815796759 /src/check_expr.cpp
parent19ea0906332e6185cd0eefe873179b9058ccd725 (diff)
`for &e, i in array` and `for k, &v in map` (alternative to passing the iterable by pointer)
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 83e44b39f..532555b0a 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -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");