diff options
| author | gingerBill <bill@gingerbill.org> | 2020-03-24 14:29:54 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-03-24 14:29:54 +0000 |
| commit | 5cbb266ef5666c1df5d25d3afe23e4a777abd22b (patch) | |
| tree | 930b1a1ed3a3cc123183218af43635ef3053a030 /src/check_stmt.cpp | |
| parent | dfc63dcb606146dcb7a4c1076e593c7991a84c9a (diff) | |
Change behaviour of `switch v in &value` to make `v` have by-reference semantics
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 67172d951..e9b6869c8 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1155,10 +1155,12 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { } } + bool is_reference = false; + if (is_ptr && cc->list.count == 1 && case_type != nullptr) { - case_type = alloc_type_pointer(case_type); + is_reference = true; } if (cc->list.count > 1) { @@ -1173,7 +1175,9 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { { Entity *tag_var = alloc_entity_variable(ctx->scope, lhs->Ident.token, case_type, EntityState_Resolved); tag_var->flags |= EntityFlag_Used; - tag_var->flags |= EntityFlag_Value; + if (!is_reference) { + tag_var->flags |= EntityFlag_Value; + } add_entity(ctx->checker, ctx->scope, lhs, tag_var); add_entity_use(ctx, lhs, tag_var); add_implicit_entity(ctx, stmt, tag_var); |