mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 00:57:04 +00:00
Merge pull request #17438 from Luukdegram/issue-17436
wasm - fix `@tagName` for signed enums
This commit is contained in:
commit
54e7f58fcb
@ -7215,12 +7215,12 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
|
||||
switch (tag_value) {
|
||||
.imm32 => |value| {
|
||||
try writer.writeByte(std.wasm.opcode(.i32_const));
|
||||
try leb.writeULEB128(writer, value);
|
||||
try leb.writeILEB128(writer, @as(i32, @bitCast(value)));
|
||||
try writer.writeByte(std.wasm.opcode(.i32_ne));
|
||||
},
|
||||
.imm64 => |value| {
|
||||
try writer.writeByte(std.wasm.opcode(.i64_const));
|
||||
try leb.writeULEB128(writer, value);
|
||||
try leb.writeILEB128(writer, @as(i64, @bitCast(value)));
|
||||
try writer.writeByte(std.wasm.opcode(.i64_ne));
|
||||
},
|
||||
else => unreachable,
|
||||
|
@ -1048,6 +1048,22 @@ test "@tagName on enum literals" {
|
||||
try comptime expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
|
||||
}
|
||||
|
||||
test "tag name with signed enum values" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||
|
||||
const LocalFoo = enum(isize) {
|
||||
alfa = 62,
|
||||
bravo = 63,
|
||||
charlie = 64,
|
||||
delta = 65,
|
||||
};
|
||||
var b = LocalFoo.bravo;
|
||||
try expect(mem.eql(u8, @tagName(b), "bravo"));
|
||||
}
|
||||
|
||||
test "enum literal casting to optional" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||
|
Loading…
Reference in New Issue
Block a user