diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-03-31 12:43:21 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-03-31 12:43:21 -0400 |
| commit | 25ac2fe8cd817977f3d5a8677cbe067ad2684d66 (patch) | |
| tree | 4282bf4c22820ce357f68e06472bdc405ce5e04b /src/ir.cpp | |
| parent | 62af7018042953f00d307508b448d42aa9d3bc65 (diff) | |
| download | zig-25ac2fe8cd817977f3d5a8677cbe067ad2684d66.tar.gz zig-25ac2fe8cd817977f3d5a8677cbe067ad2684d66.zip | |
fix anon enum literal used with switch on union(enum)
closes #2141
closes #2142
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 0833bb580c..52f8f2b935 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -17188,11 +17188,18 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru assert(target_value_ptr->value.type->id == ZigTypeIdPointer); ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; if (target_type->id == ZigTypeIdUnion) { - ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad); + ZigType *enum_type = target_type->data.unionation.tag_type; + assert(enum_type != nullptr); + assert(enum_type->id == ZigTypeIdEnum); + + IrInstruction *casted_prong_value = ir_implicit_cast(ira, prong_value, enum_type); + if (type_is_invalid(casted_prong_value->value.type)) + return ira->codegen->invalid_instruction; + + ConstExprValue *prong_val = ir_resolve_const(ira, casted_prong_value, UndefBad); if (!prong_val) return ira->codegen->invalid_instruction; - assert(prong_value->value.type->id == ZigTypeIdEnum); TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag); if (instr_is_comptime(target_value_ptr)) { |
