| author | |
| committer | |
| log | fc1a5cd9e74faf19e5974c733b0bcd9444d48b7b |
| tree | 3638e0eb93d37713bb03ed3c53b6921b9267c1a8 |
| parent | 9dd4fb4130a71d2aaaaa361d8ee0b7135cb84162 |
3 files changed, 10 insertions(+), 5 deletions(-)
src/Sema.zig+5| ... | ... | @@ -10054,6 +10054,11 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10054 | 10054 | const operand_ty = sema.typeOf(operand); |
| 10055 | 10055 | |
| 10056 | 10056 | const enum_ty = switch (operand_ty.zigTypeTag()) { |
| 10057 | .EnumLiteral => { | |
| 10058 | const val = try sema.resolveConstValue(block, operand_src, operand); | |
| 10059 | const bytes = val.castTag(.enum_literal).?.data; | |
| 10060 | return sema.addStrLit(block, bytes); | |
| 10061 | }, | |
| 10057 | 10062 | .Enum => operand_ty, |
| 10058 | 10063 | .Union => operand_ty.unionTagType() orelse { |
| 10059 | 10064 | const decl = operand_ty.getOwnerDecl(); |
test/behavior/enum_llvm.zig+5| ... | ... | @@ -39,6 +39,11 @@ test "tag name with assigned enum values" { |
| 39 | 39 | try expect(mem.eql(u8, @tagName(b), "B")); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | test "@tagName on enum literals" { | |
| 43 | try expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); | |
| 44 | comptime try expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); | |
| 45 | } | |
| 46 | ||
| 42 | 47 | const Bar = enum { A, B, C, D }; |
| 43 | 48 | |
| 44 | 49 | test "enum literal casting to optional" { |
test/behavior/enum_stage1.zig-5| ... | ... | @@ -43,11 +43,6 @@ test "enum literal casting to error union with payload enum" { |
| 43 | 43 | try expect((try bar) == Bar.B); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | test "tagName on enum literals" { | |
| 47 | try expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); | |
| 48 | comptime try expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); | |
| 49 | } | |
| 50 | ||
| 51 | 46 | test "method call on an enum" { |
| 52 | 47 | const S = struct { |
| 53 | 48 | const E = enum { |