authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-09-26 08:01:09-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-10-01 18:09:15-06:00
log61ce72a38cedfcbd8450922cbf1cadc0c1682928
tree92a48c3dc6511b2d296bc0dc28cca811c3a9ce65
parent0228887b943dd7e70f7c5cc56e3993769342abf2
signature Commit is signed but in an unrecognized format.

Allow enums with explicit extern-allowed tag types in extern types

Closes https://github.com/ziglang/zig/issues/1467

2 files changed, 15 insertions(+), 4 deletions(-)

src/stage1/all_types.hpp+1
...@@ -1456,6 +1456,7 @@ struct ZigTypeEnum {...@@ -1456,6 +1456,7 @@ struct ZigTypeEnum {
1456 ContainerLayout layout;1456 ContainerLayout layout;
1457 ResolveStatus resolve_status;1457 ResolveStatus resolve_status;
14581458
1459 bool has_explicit_tag_type;
1459 bool non_exhaustive;1460 bool non_exhaustive;
1460 bool resolve_loop_flag;1461 bool resolve_loop_flag;
1461};1462};
src/stage1/analyze.cpp+14-4
...@@ -1802,10 +1802,18 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {...@@ -1802,10 +1802,18 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {
1802 }1802 }
1803 return type_allowed_in_extern(g, child_type, result);1803 return type_allowed_in_extern(g, child_type, result);
1804 }1804 }
1805 case ZigTypeIdEnum:1805 case ZigTypeIdEnum: {
1806 *result = type_entry->data.enumeration.layout == ContainerLayoutExtern ||1806 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
1807 type_entry->data.enumeration.layout == ContainerLayoutPacked;1807 return err;
1808 return ErrorNone;1808 ZigType *tag_int_type = type_entry->data.enumeration.tag_int_type;
1809 if (type_entry->data.enumeration.has_explicit_tag_type) {
1810 return type_allowed_in_extern(g, tag_int_type, result);
1811 } else {
1812 *result = type_entry->data.enumeration.layout == ContainerLayoutExtern ||
1813 type_entry->data.enumeration.layout == ContainerLayoutPacked;
1814 return ErrorNone;
1815 }
1816 }
1809 case ZigTypeIdUnion:1817 case ZigTypeIdUnion:
1810 *result = type_entry->data.unionation.layout == ContainerLayoutExtern ||1818 *result = type_entry->data.unionation.layout == ContainerLayoutExtern ||
1811 type_entry->data.unionation.layout == ContainerLayoutPacked;1819 type_entry->data.unionation.layout == ContainerLayoutPacked;
...@@ -2639,9 +2647,11 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {...@@ -2639,9 +2647,11 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
2639 if (decl_node->type == NodeTypeContainerDecl) {2647 if (decl_node->type == NodeTypeContainerDecl) {
2640 if (decl_node->data.container_decl.init_arg_expr != nullptr) {2648 if (decl_node->data.container_decl.init_arg_expr != nullptr) {
2641 wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr);2649 wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr);
2650 enum_type->data.enumeration.has_explicit_tag_type = true;
2642 }2651 }
2643 } else {2652 } else {
2644 wanted_tag_int_type = enum_type->data.enumeration.tag_int_type;2653 wanted_tag_int_type = enum_type->data.enumeration.tag_int_type;
2654 enum_type->data.enumeration.has_explicit_tag_type = true;
2645 }2655 }
26462656
2647 if (wanted_tag_int_type != nullptr) {2657 if (wanted_tag_int_type != nullptr) {