diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-12-05 20:51:49 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-12-05 20:51:49 -0500 |
| commit | b66fb7ceae9029935e5cf3c3752d240a74b6cd7c (patch) | |
| tree | b578fe95e0e4c9179a21989b9e19934d54ef6287 | |
| parent | 6018dbd3391d1e71eef650aff700eab53074c308 (diff) | |
| download | zig-b66fb7ceae9029935e5cf3c3752d240a74b6cd7c.tar.gz zig-b66fb7ceae9029935e5cf3c3752d240a74b6cd7c.zip | |
revert to master branch ir.cpp, fixes issue better than this branch
| -rw-r--r-- | src/ir.cpp | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index e31cd2d1bf..86fa8c3566 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -8490,6 +8490,16 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour if (type_is_invalid(wanted_type)) return ira->codegen->invalid_instruction; + if (actual_type != wanted_type->data.enumeration.tag_int_type) { + ir_add_error(ira, source_instr, + buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'", + buf_ptr(&actual_type->name), + buf_ptr(&wanted_type->data.enumeration.tag_int_type->name))); + return ira->codegen->invalid_instruction; + } + + assert(actual_type->id == TypeTableEntryIdInt); + if (instr_is_comptime(target)) { ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) @@ -8513,17 +8523,6 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour return result; } - if (actual_type != wanted_type->data.enumeration.tag_int_type) { - ir_add_error(ira, source_instr, - buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'", - buf_ptr(&actual_type->name), - buf_ptr(&wanted_type->data.enumeration.tag_int_type->name))); - return ira->codegen->invalid_instruction; - } - - assert(actual_type->id == TypeTableEntryIdInt); - - IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope, source_instr->source_node, target); result->value.type = wanted_type; @@ -8893,20 +8892,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } } - // explicit cast from integer to enum type with no payload - if ((actual_type->id == TypeTableEntryIdInt || actual_type->id == TypeTableEntryIdNumLitInt) && - wanted_type->id == TypeTableEntryIdEnum) - { - return ir_analyze_int_to_enum(ira, source_instr, value, wanted_type); - } - - // explicit cast from enum type with no payload to integer - if ((wanted_type->id == TypeTableEntryIdInt || wanted_type->id == TypeTableEntryIdNumLitInt) && - actual_type->id == TypeTableEntryIdEnum) - { - return ir_analyze_enum_to_int(ira, source_instr, value, wanted_type); - } - // explicit cast from number literal to another type // explicit cast from number literal to &const integer if (actual_type->id == TypeTableEntryIdNumLitFloat || @@ -8981,6 +8966,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst return ir_analyze_int_to_err(ira, source_instr, value); } + // explicit cast from integer to enum type with no payload + if (actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdEnum) { + return ir_analyze_int_to_enum(ira, source_instr, value, wanted_type); + } + + // explicit cast from enum type with no payload to integer + if (wanted_type->id == TypeTableEntryIdInt && actual_type->id == TypeTableEntryIdEnum) { + return ir_analyze_enum_to_int(ira, source_instr, value, wanted_type); + } + // explicit cast from union to the enum type of the union if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) { type_ensure_zero_bits_known(ira->codegen, actual_type); |
