From 77a1a216d2b3ceb956869ba1716fbb6c0c7eabe8 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 7 May 2018 16:43:20 -0400 Subject: tagged union field access prioritizes members over enum tags closes #959 --- src/ir.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/ir.cpp') 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))); -- cgit v1.2.3