diff --git a/src/Sema.zig b/src/Sema.zig index f1431272db..8d27553f94 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -10054,6 +10054,11 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const operand_ty = sema.typeOf(operand); const enum_ty = switch (operand_ty.zigTypeTag()) { + .EnumLiteral => { + const val = try sema.resolveConstValue(block, operand_src, operand); + const bytes = val.castTag(.enum_literal).?.data; + return sema.addStrLit(block, bytes); + }, .Enum => operand_ty, .Union => operand_ty.unionTagType() orelse { const decl = operand_ty.getOwnerDecl(); diff --git a/test/behavior/enum_llvm.zig b/test/behavior/enum_llvm.zig index 700e396087..6d57aac2c1 100644 --- a/test/behavior/enum_llvm.zig +++ b/test/behavior/enum_llvm.zig @@ -39,6 +39,11 @@ test "tag name with assigned enum values" { try expect(mem.eql(u8, @tagName(b), "B")); } +test "@tagName on enum literals" { + try expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); + comptime try expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); +} + const Bar = enum { A, B, C, D }; test "enum literal casting to optional" { diff --git a/test/behavior/enum_stage1.zig b/test/behavior/enum_stage1.zig index 50955d4388..0f9c1dc6f5 100644 --- a/test/behavior/enum_stage1.zig +++ b/test/behavior/enum_stage1.zig @@ -43,11 +43,6 @@ test "enum literal casting to error union with payload enum" { try expect((try bar) == Bar.B); } -test "tagName on enum literals" { - try expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); - comptime try expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); -} - test "method call on an enum" { const S = struct { const E = enum {