aboutsummaryrefslogtreecommitdiff
path: root/src/check_stmt.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-23 11:50:02 +0100
committergingerBill <bill@gingerbill.org>2021-08-23 11:50:02 +0100
commitcba0bd30f548c6a757a3ed5fb994380a4a10aa2e (patch)
tree2a531f0d0d4609e84ab5402f6604a1268fc125cf /src/check_stmt.cpp
parent276d4b8f0d5c5bcff4b83bab12746dd80e10fc90 (diff)
Add suggestions when trying to take the address the a value from a `for`/`switch` statement
Diffstat (limited to 'src/check_stmt.cpp')
-rw-r--r--src/check_stmt.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index 2e407e6c6..6943f3d97 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -1343,6 +1343,7 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
tag_var->flags |= EntityFlag_Used;
if (!is_reference) {
tag_var->flags |= EntityFlag_Value;
+ tag_var->flags |= EntityFlag_SwitchValue;
}
add_entity(ctx, ctx->scope, lhs, tag_var);
add_entity_use(ctx, lhs, tag_var);
@@ -1921,6 +1922,8 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
auto lhs = slice_make<Ast *>(temporary_allocator(), rhs.count);
slice_copy(&lhs, rs->vals);
+ isize addressable_index = cast(isize)is_map;
+
for_array(i, rhs) {
if (lhs[i] == nullptr) {
continue;
@@ -1940,11 +1943,11 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
if (found == nullptr) {
entity = alloc_entity_variable(ctx->scope, token, type, EntityState_Resolved);
entity->flags |= EntityFlag_Value;
- if (use_by_reference_for_value) {
- if (i == 0 && !is_map) {
- entity->flags &= ~EntityFlag_Value;
- } else if (i == 1 && is_map) {
+ if (i == addressable_index) {
+ if (use_by_reference_for_value) {
entity->flags &= ~EntityFlag_Value;
+ } else {
+ entity->flags |= EntityFlag_ForValue;
}
}
if (is_soa) {