zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ddce76059b1631f3eddc3c09615b26698210ba9e (tree)
parent d078d08e4f661c1b0bee31d7852e5e6058d54b11
Author: Veikka Tuominen <git@vexu.eu>
Date:   Mon,  5 Dec 2022 18:17:33 +0200

Sema: add error for `@tagName` on empty enum

Diffstat:
Msrc/Sema.zig | 7+++++++
1 file changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -17877,6 +17877,13 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air operand_ty.fmt(mod), }), }; + if (enum_ty.enumFieldCount() == 0) { + // TODO I don't think this is the correct way to handle this but + // it prevents a crash. + return sema.fail(block, operand_src, "cannot get @tagName of empty enum '{}'", .{ + enum_ty.fmt(mod), + }); + } const enum_decl_index = enum_ty.getOwnerDecl(); const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src); if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| {