| ... | ... | @@ -8629,6 +8629,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8629 | 8629 | .{src}, |
| 8630 | 8630 | ); |
| 8631 | 8631 | }; |
| 8632 | |
| 8632 | 8633 | break :blk try sema.unionToTag(block, tag_ty, operand, operand_src); |
| 8633 | 8634 | }, |
| 8634 | 8635 | else => { |
| ... | ... | @@ -8638,14 +8639,25 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8638 | 8639 | }, |
| 8639 | 8640 | }; |
| 8640 | 8641 | const enum_tag_ty = sema.typeOf(enum_tag); |
| 8641 | | |
| 8642 | 8642 | const int_tag_ty = enum_tag_ty.intTagType(mod); |
| 8643 | 8643 | |
| 8644 | // TODO: use correct solution |
| 8645 | // https://github.com/ziglang/zig/issues/15909 |
| 8646 | if (enum_tag_ty.enumFieldCount(mod) == 0 and !enum_tag_ty.isNonexhaustiveEnum(mod)) { |
| 8647 | return sema.fail(block, operand_src, "cannot use @intFromEnum on empty enum '{}'", .{ |
| 8648 | enum_tag_ty.fmt(mod), |
| 8649 | }); |
| 8650 | } |
| 8651 | |
| 8644 | 8652 | if (try sema.typeHasOnePossibleValue(enum_tag_ty)) |opv| { |
| 8645 | 8653 | return Air.internedToRef((try mod.getCoerced(opv, int_tag_ty)).toIntern()); |
| 8646 | 8654 | } |
| 8647 | 8655 | |
| 8648 | 8656 | if (try sema.resolveValue(enum_tag)) |enum_tag_val| { |
| 8657 | if (enum_tag_val.isUndef(mod)) { |
| 8658 | return mod.undefRef(int_tag_ty); |
| 8659 | } |
| 8660 | |
| 8649 | 8661 | const val = try enum_tag_val.intFromEnum(enum_tag_ty, mod); |
| 8650 | 8662 | return Air.internedToRef(val.toIntern()); |
| 8651 | 8663 | } |
| ... | ... | @@ -20944,6 +20956,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20944 | 20956 | if (enum_ty.enumFieldCount(mod) == 0) { |
| 20945 | 20957 | // TODO I don't think this is the correct way to handle this but |
| 20946 | 20958 | // it prevents a crash. |
| 20959 | // https://github.com/ziglang/zig/issues/15909 |
| 20947 | 20960 | return sema.fail(block, operand_src, "cannot get @tagName of empty enum '{}'", .{ |
| 20948 | 20961 | enum_ty.fmt(mod), |
| 20949 | 20962 | }); |