diff options
| author | Tadeo Kondrak <me@tadeo.ca> | 2020-09-26 08:01:09 -0600 |
|---|---|---|
| committer | Tadeo Kondrak <me@tadeo.ca> | 2020-10-01 18:09:15 -0600 |
| commit | 61ce72a38cedfcbd8450922cbf1cadc0c1682928 (patch) | |
| tree | 92a48c3dc6511b2d296bc0dc28cca811c3a9ce65 /src/stage1/analyze.cpp | |
| parent | 0228887b943dd7e70f7c5cc56e3993769342abf2 (diff) | |
| download | zig-61ce72a38cedfcbd8450922cbf1cadc0c1682928.tar.gz zig-61ce72a38cedfcbd8450922cbf1cadc0c1682928.zip | |
Allow enums with explicit extern-allowed tag types in extern types
Closes https://github.com/ziglang/zig/issues/1467
Diffstat (limited to 'src/stage1/analyze.cpp')
| -rw-r--r-- | src/stage1/analyze.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index 369c284684..64251c1f0c 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -1802,10 +1802,18 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { } return type_allowed_in_extern(g, child_type, result); } - case ZigTypeIdEnum: - *result = type_entry->data.enumeration.layout == ContainerLayoutExtern || - type_entry->data.enumeration.layout == ContainerLayoutPacked; - return ErrorNone; + case ZigTypeIdEnum: { + if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) + return err; + ZigType *tag_int_type = type_entry->data.enumeration.tag_int_type; + if (type_entry->data.enumeration.has_explicit_tag_type) { + return type_allowed_in_extern(g, tag_int_type, result); + } else { + *result = type_entry->data.enumeration.layout == ContainerLayoutExtern || + type_entry->data.enumeration.layout == ContainerLayoutPacked; + return ErrorNone; + } + } case ZigTypeIdUnion: *result = type_entry->data.unionation.layout == ContainerLayoutExtern || type_entry->data.unionation.layout == ContainerLayoutPacked; @@ -2639,9 +2647,11 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { if (decl_node->type == NodeTypeContainerDecl) { if (decl_node->data.container_decl.init_arg_expr != nullptr) { wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr); + enum_type->data.enumeration.has_explicit_tag_type = true; } } else { wanted_tag_int_type = enum_type->data.enumeration.tag_int_type; + enum_type->data.enumeration.has_explicit_tag_type = true; } if (wanted_tag_int_type != nullptr) { |
