diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-12-05 21:10:47 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-12-05 21:10:47 -0500 |
| commit | 2715f6fdb8bca1c88c58dac047889711359e193b (patch) | |
| tree | 52fcb1d48f7a3198d7718e57a6df2c3bc742a157 /src/ir.cpp | |
| parent | 960914a073c367883c9fdf54e900890a6aefc05f (diff) | |
| download | zig-2715f6fdb8bca1c88c58dac047889711359e193b.tar.gz zig-2715f6fdb8bca1c88c58dac047889711359e193b.zip | |
allow implicit cast from union to its enum tag type
closes #642
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 86fa8c3566..0ab63a02fe 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -7468,6 +7468,17 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, } } + // implicit union to its enum tag type + if (expected_type->id == TypeTableEntryIdEnum && actual_type->id == TypeTableEntryIdUnion && + (actual_type->data.unionation.decl_node->data.container_decl.auto_enum || + actual_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) + { + type_ensure_zero_bits_known(ira->codegen, actual_type); + if (actual_type->data.unionation.tag_type == expected_type) { + return ImplicitCastMatchResultYes; + } + } + // implicit enum to union which has the enum as the tag type if (expected_type->id == TypeTableEntryIdUnion && actual_type->id == TypeTableEntryIdEnum && (expected_type->data.unionation.decl_node->data.container_decl.auto_enum || |
