aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-05-07 16:43:20 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-05-07 16:43:20 -0400
commit77a1a216d2b3ceb956869ba1716fbb6c0c7eabe8 (patch)
treef4b33b6b983451391e4d627acc45411e3730c8d5 /src
parent2f633452bb337a3f173c4fd82c2b4a0880f981f5 (diff)
downloadzig-77a1a216d2b3ceb956869ba1716fbb6c0c7eabe8.tar.gz
zig-77a1a216d2b3ceb956869ba1716fbb6c0c7eabe8.zip
tagged union field access prioritizes members over enum tags
closes #959
Diffstat (limited to 'src')
-rw-r--r--src/ir.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 5339931590..cdf56f7fee 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -13736,7 +13736,16 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
create_const_enum(child_type, &field->value), child_type,
ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
}
- } else if (child_type->id == TypeTableEntryIdUnion &&
+ }
+ ScopeDecls *container_scope = get_container_scope(child_type);
+ if (container_scope != nullptr) {
+ auto entry = container_scope->decl_table.maybe_get(field_name);
+ Tld *tld = entry ? entry->value : nullptr;
+ if (tld) {
+ return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
+ }
+ }
+ if (child_type->id == TypeTableEntryIdUnion &&
(child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
child_type->data.unionation.decl_node->data.container_decl.auto_enum))
{
@@ -13753,14 +13762,6 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
}
}
- ScopeDecls *container_scope = get_container_scope(child_type);
- if (container_scope != nullptr) {
- auto entry = container_scope->decl_table.maybe_get(field_name);
- Tld *tld = entry ? entry->value : nullptr;
- if (tld) {
- return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
- }
- }
ir_add_error(ira, &field_ptr_instruction->base,
buf_sprintf("container '%s' has no member called '%s'",
buf_ptr(&child_type->name), buf_ptr(field_name)));